2

私を助けてください。Unicodeをサーブレットに投稿するときに問題が発生します。私は多くの方法を試しましたが。私はアンドロイドからリクエストを送信します:

HttpPost httppost = new HttpPost(Constants.ADD_REPORT_URL);
DefaultHttpClient httpClient = new DefaultHttpClient();
MultipartEntity entity = new MultipartEntity(
            HttpMultipartMode.BROWSER_COMPATIBLE, "text/html",
            Charset.forName("UTF-8"));
// this.profile.userId));
entity.addPart(User.TOKEN,new StringBody("unicode over here"));
...
httppost.setEntity(entity);

そしてサーブレットで

request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter writer = response.getWriter();
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    Map<String, String> map = new HashMap<String, String>();
    String linkImage = "";
    if (!isMultipart) {
        System.out.println("File Not Uploaded");
    } else {
        System.err.println("A file is ready to upload");
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = null;
        try {
            items = upload.parseRequest(request);
            // System.out.println("items: " + items);
        } catch (FileUploadException e) {
            e.printStackTrace();
        }
        Iterator itr = items.iterator();
        while (itr.hasNext()) {
            FileItem item = (FileItem) itr.next();
            // part is text form
            if (item.isFormField()) {
                System.out.println("content type:" + item.getContentType());
                String name = item.getFieldName();
                System.out.println("name: " + name);

しかし、文字列は印刷されます"362 Cu Giy, Dch Vng, Cu Giy,"

4

0 に答える 0