后台如何使用jsp接收swfupload下传的文件
后台怎么使用jsp接收swfupload上传的文件
在后台接收文件,如果这段代码写在servlet中可以正常接收
upload_url: uploadfileservlet
但是同样的代码如果写在jsp中,就接收不到文件
upload_url: uploadfile.jsp
------解决方案--------------------
请问是什么原因? 怎么解决啊
在后台接收文件,如果这段代码写在servlet中可以正常接收
upload_url: uploadfileservlet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
uploadFile(request,response);
}
private void uploadFile(HttpServletRequest request, HttpServletResponse response){
String dir = "d:/upload";
File file = new File(dir);
if(!file.exists())
file.mkdirs();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
//防止中文文件名乱码
upload.setHeaderEncoding("UTF-8");
try {
List<FileItem> items = upload.parseRequest(request);
if (items != null) {
Iterator<FileItem> itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {
continue;
} else {
//File fullFile=new File(item.getName());
File savedFile=new File(dir+File.separator+item.getName());
item.write(savedFile);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
//结束upload. 如果没有这一行, 浏览器里面一直是uploading....
try {
response.getOutputStream().println("200 OK");
} catch (IOException e) {
e.printStackTrace();
}
}
但是同样的代码如果写在jsp中,就接收不到文件
upload_url: uploadfile.jsp
------解决方案--------------------
请问是什么原因? 怎么解决啊