q666123 发表于 2017-1-5 09:23:13

Jsp apache-common-fileupload 文件上传 乱码

  在action里使用fileupload时,从reqeust得到的中文数据为乱码,尝试使用了
Java代码
1. DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("utf-8")

2.jsp文件的request.setCharacterEncoding("UTF-8");

3. FileItem item = (FileItem) itr.next();

String value = new String(item.getString().getBytes()) ;

均无效!

最终的解决办法是 使用 org.apache.commons.fileupload组件里的一个方法:

String value = new String(item.getString("UTF-8")
页: [1]
查看完整版本: Jsp apache-common-fileupload 文件上传 乱码