09-04
28
[转帖]上传时,出现the request doesn't contain a multipart/form
作者:Java伴侣 日期:2009-04-28
org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
jsp页面:
<form name="myform" id="myform" enctype="multipart/form-data"
method="post" onsubmit="return picForm_Validator(this)">
<p align="center">
文件上传
<input type="File" name="fileupload" value="upload" />
<input type="submit" value="上传">
<input type="reset" value="取消">(最大5MB)
</p>
</form>
action中:
response.setContentType("text/html; charset=GBK");
try {
request.setCharacterEncoding("GBk");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setCharacterEncoding("GBk");
System.out.println("contentType=======" + request.getContentType());
FilmNews film = new FilmNews();
Date date = new Date();
try {
DiskFileUpload upload=new DiskFileUpload();
upload.setSizeMax(5*1024);
upload.setSizeThreshold(1024 * 1024);
List uploadlist=upload.parseRequest(request);
// FileItemFactory factory = new DiskFileItemFactory();
// ServletFileUpload fu = new ServletFileUpload(factory);
这样的的话会出现:
org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:885)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:310)
at com.tonglian.sneduoffice.action.FileUploadAction.execute(FileUploadAction.java:58)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.tonglian.core.web.filter.SetEncodeFilter.doFilter(SetEncodeFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
程序发生错误,抛出异常为 the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
这个错误的原因是:form表单提交需要用action这个属性,用onsubmit方法虽然能够提交成功,可是有些数据丢失。把onsubmit换成action就ok。
这个小problem让我解决了快1天,开来我的水平很菜呀,呵呵。。。,努力!!!
jsp页面:
<form name="myform" id="myform" enctype="multipart/form-data"
method="post" onsubmit="return picForm_Validator(this)">
<p align="center">
文件上传
<input type="File" name="fileupload" value="upload" />
<input type="submit" value="上传">
<input type="reset" value="取消">(最大5MB)
</p>
</form>
action中:
response.setContentType("text/html; charset=GBK");
try {
request.setCharacterEncoding("GBk");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setCharacterEncoding("GBk");
System.out.println("contentType=======" + request.getContentType());
FilmNews film = new FilmNews();
Date date = new Date();
try {
DiskFileUpload upload=new DiskFileUpload();
upload.setSizeMax(5*1024);
upload.setSizeThreshold(1024 * 1024);
List uploadlist=upload.parseRequest(request);
// FileItemFactory factory = new DiskFileItemFactory();
// ServletFileUpload fu = new ServletFileUpload(factory);
这样的的话会出现:
org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:885)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:310)
at com.tonglian.sneduoffice.action.FileUploadAction.execute(FileUploadAction.java:58)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.tonglian.core.web.filter.SetEncodeFilter.doFilter(SetEncodeFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
程序发生错误,抛出异常为 the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
这个错误的原因是:form表单提交需要用action这个属性,用onsubmit方法虽然能够提交成功,可是有些数据丢失。把onsubmit换成action就ok。
这个小problem让我解决了快1天,开来我的水平很菜呀,呵呵。。。,努力!!!
评论: 0 | 引用: 0 | 查看次数: 1042
发表评论