request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try{
List items = upload.parseRequest(request);
java.util.Iterator itr = items.iterator();
while(itr.hasNext()){
FileItem item = (FileItem)itr.next();
if(item.isFormField()){
System.out.println("纯表单");
}else{
if(item.getName()!=null&&!item.getName().equals("")){
System.out.println(this.getServletContext().getRealPath("/"));
System.out.println("文件大小:"+item.getSize());
System.out.println("文件类型:"+item.getContentType());
System.out.println("文件名:"+item.getName());
File tempFile = new File(item.getName());
File file = new File(this.getServletContext().getRealPath("/")+savePath+tempFile.getName());
item.write(file);
}
}
}
}catch(Exception e){
e.printStackTrace();
}
我的web工程目录下有headImages的文件夹,为什么未抛任何异常,打开文件夹,里面还是什么都没有? |
|