`
yuexiaowen
  • 浏览: 121614 次
  • 性别: Icon_minigender_2
  • 来自: 咸阳
社区版块
存档分类
最新评论

上传时,出现the request doesn't contain a multipart/form

阅读更多
  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天,开来我的水平很菜呀,呵呵。。。,努力!!!
分享到:
评论
4 楼 yds3300376yd 2013-11-01  
我也遇到上述问题了,不过代码不在我这,还没开始改~~~
3 楼 孤狼A组 2013-02-01  
在提交表单里加上这一句:enctype="multipart/form-data",就可以了。
2 楼 lxs647 2010-07-14  
我的也是一样儿的,问题的关键不在这儿、、、
1 楼 guoguo1010 2010-06-17  
不对吧  我的Form本来就有Action啊 

相关推荐

    cocoscreater推箱子.rar

    推箱子,cocoscreater js源码,仅供参考学习

    pdfbox jar包

    pdfbox2.0.2.jar包,把后面的‘-zip’删掉就可以用,因为怕冲突。有人既然要18个下载分,我觉得这不是共享,别人有需要的时候,确无法下载。不能用可以找我

    pdfbox最新版

    全部pdfbox的jar

    CSU825DINGYI

    series contain a 16K/8K/4K/2K bytes of main Flash EPROM; a 256/128 bytes of RAM; 256/128 bytes NVM Data Flash EPROM; two 8-bit bi-directional , one 2-bit bi-directional and bit-addressable I/O ports...

    一个跨平台的CString源码

    // the string did NOT contain any of the given characters // // 2002-OCT-21 - Many thanks to Paul DeMarco who was invaluable in helping me // get this code working with Borland's free compiler as well...

    SSD7 选择题。Multiple-Choice

    (b) the name of the table, the names of the table's attributes, the data types of the table's attributes, the formats of the table's attributes, and the maximum number of rows that the table can have...

    a project model for the FreeBSD Project.7z

    A project model for the FreeBSD Project Niklas Saers Copyright © 2002-2005 Niklas Saers [ Split HTML / Single HTML ] Table of Contents Foreword 1 Overview 2 Definitions 2.1. Activity 2.2. Process ...

    xcode报错SDK does not contain 'libarclite' at the path

    xcode报错SDK does not contain 'libarclite' at the path

    google api php client

    The `authorize` method returns an authorized [Guzzle Client](http://docs.guzzlephp.org/), so any request made using the client will contain the corresponding authorization. ```php // create the ...

    JSP Simple Examples

    A form can contain checkboxes, textfields, radio- buttons and many more. Forms are used to pass user- data to a specified URL which is specified in the action attribute of the form tag. Interface ...

    Sakemail

    .- Reduced the line sleep to 30 (tell me if this value doesn‘t work for you).27/4/981.7.0- Fixed a memory leak, thanks to Don Higgins.- Moved the string esErrorInFormatOfMsg to a property of SakPOP.-...

    用OpenGL 导入 3DS 源文件

    don't do this, some of the UI elements of your application will remain in the language of the operating system. /////////////////////////////////////////////////////////////////////////////

    数位板压力测试

    The device must have a point-ing ap¬para¬tus or method (such as a stylus, or a finger touching a touch pad), called the cursor, that de¬fines the current position. The cursor must be able to ...

    VB.NET多款风格渐变和无规则按钮

    Classes that don't support this are serialized and stored with the mimetype set. The mimetype is used for serialized objects, and tells the ResXResourceReader how to depersist the object. This...

    Python 爬虫之超链接 url中含有中文出错及解决办法

    这个错误是由于超链接中含有中文引起的,超链接默认是用ascii编码的,所以不能直接出现中文,若要出现中文, 解决方法如下: import urllib from urllib.request import urlopen link=...

    基于VC++的绘图程序

    don't do this, some of the UI elements of your application will remain in the language of the operating system. /////////////////////////////////////////////////////////////////////////////

    squashfs1.3r3.tar.gz

    doesn't exist it will be created, if it does exist and a squashfs filesystem exists on it, mksquashfs will append. The -noappend option will write a new filesystem irrespective of whether an existing ...

    华科VC++画图应用程序

    don't do this, some of the UI elements of your application will remain in the language of the operating system. /////////////////////////////////////////////////////////////////////////////

    图像处理中关于小波变换的源代码

    don't do this, some of the UI elements of your application will remain in the language of the operating system. /////////////////////////////////////////////////////////////////////////////

    可以用来屏蔽热键的VC源代码

    don't do this, some of the UI elements of your application will remain in the language of the operating system. /////////////////////////////////////////////////////////////////////////////

Global site tag (gtag.js) - Google Analytics