请帮帮我。 将unicode发布到servlet时遇到问题。 虽然我尝试了很多方法。 我从android发送请求:
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);
在servlet中
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,"