DiskFileUpload 中文乱码 解决方法

DiskFileUpload upload = new DiskFileUpload();
upload.setHeaderEncoding("utf8"); // 此句为主要代码
upload.setSizeMax(yourMaxRequestSize);
upload.setSizeThreshold(buf);

List<FileItem> items = upload.parseRequest(request);
Map<String, Serializable> fields = new HashMap<String, Serializable>();
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField())
fields.put(item.getFieldName(), item);
}
FileItem uploadFile = (FileItem) fields.get("filedata"); //获取表单的上传文件
String fileNameLong = uploadFile.getName(); //获取文件上传路径名称

System.out.println("--------------uploadFileName:" + fileNameLong);

 

你可能感兴趣的:(upload,DiskFileUpload)