我正在使用jsp进行文件上传,使用common-fileupload.It在spring blaze-ds和flex环境下工作正常。但是当我在struts和flex框架中使用相同的jsp时,我收到以下错误:
org.apache.jasper.JasperException:在第69行处理JSP页面/pages/Template_Upload.jsp时发生异常
66: FileItemFactory factory = new DiskFileItemFactory();
67: ServletFileUpload upload = new ServletFileUpload(factory);
68: //List<FileItem> items = upload.parseRequest(request);
69: List<FileItem> items = upload.parseRequest(request);
70: out.println(items);
71: int counter = 0;
72:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.pages.Template_005fUpload_jsp._jspService(Template_005fUpload_jsp.java:202)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:908)
org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
org.apache.jsp.pages.Template_005fUpload_jsp._jspService(Template_005fUpload_jsp.java:136)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
请帮帮我.. 在此先感谢
已更新 这是我的JSP。我将项目大小设置为0.因此它没有进入for循环并在指定路径中创建文件。
String uploadpath = "C:\\XXXX\\XXXXX\\DataToUpload";
uploadDir = uploadpath;
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);
out.println(items);
int counter = 0;
for(FileItem item : items) {
File uploadedFile = new File(uploadDir + File.separator + item.getName());
uploadedFile.createNewFile();
try
{
item.write(uploadedFile);
}
catch(IOException e) {
log.error("error" + e);
}
}
答案 0 :(得分:0)
我的表单不包含
enctype="multipart/form-data"
然后,您收到错误并不奇怪
org.apache.commons.fileupload.FileUploadBase $ InvalidContentTypeException:请求不包含multipart / form-data 或multipart / mixed流,内容类型标头为null
我不知道Flex文件上传,但上传文件时,内容必须为multipart/form-data
。
如果未指定内容类型,则使用默认内容类型:application/x-www-form-urlencoded