public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("进入");
try {
request.setCharacterEncoding("gb2312");
DiskFileUpload dfu = new DiskFileUpload();
dfu.setSizeMax(4194304);//最大上传文件4M
dfu.setSizeThreshold(4096);//缓冲大小
dfu.setRepositoryPath("H:\three");//存放临时文件地址
List<FileItem> fi= dfu.parseRequest(request);
System.out.println(fi);
for(FileItem file:fi)
{
byte [] b= file.getName().getBytes("gb2312");
System.out.println(b);
String fileName = new String(b);
System.out.println(fileName);
int index = fileName.lastIndexOf("\\");
System.out.println(index);
String realName = fileName.substring(index );
System.out.println(realName);
File f = new File("H:\three" + realName);
file.write(f);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("info", "添加成功!");
return mapping.findForward("back");
}
为什么dfu.parseRequest(request)为空,接收不到文件.