`
yuexiaowen
  • 浏览: 124628 次
  • 性别: 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啊 

相关推荐

    multipartform-data 参数传递

    在Web开发中,`multipart/form-data`是一种用于发送表单数据的编码类型,尤其适用于处理文件上传。此编码方式能够使客户端浏览器将表单中的普通文本字段与文件字段一起发送到服务器端进行处理。 #### 标题解析 - **...

    cocoscreater推箱子.rar

    1. 路径规划:对于复杂的关卡,可以引入A*寻路算法,帮助玩家找到最优解。 2. 动画效果:添加箱子移动和玩家行动的动画,提升游戏体验。 3. 声音效果:通过CocosCreator的音频管理模块,加入声音效果,如移动声、...

    pdfbox jar包

    PDFBox 2.0.2支持创建符合PDF/A-1b、PDF/A-2b和PDF/A-3b标准的文件。 2. **文本和图像提取**:用户可以通过PDFBox库轻松提取PDF文档中的文本和图像,这对于数据挖掘、文档转换或内容分析等任务非常有用。 3. **...

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

    当Xcode报出“SDK does not contain 'libarclite' at the path”错误时,这通常意味着你的项目设置或者使用的SDK版本与ARC不兼容,或者libarclite库没有正确地链接到你的项目中。这可能是以下原因导致的: 1. **...

    pdfbox最新版

    7. **PDF/A兼容性**:PDFBox还支持创建符合PDF/A标准的文档,这是一种用于长期保存的PDF格式,确保内容的可读性和持久性。 8. **OCR集成**:虽然PDFBox本身不包含OCR(光学字符识别)功能,但可以通过与其他OCR库如...

    java实现文件上传

    在Java编程环境中,实现文件上传是一项常见的任务,特别是在构建Web应用程序时。文件上传功能允许用户通过Web界面上传本地文件到服务器,这对于数据交换、图片上传、文档共享等场景至关重要。在本篇中,我们将深入...

    SDK does not contain 'libarclite'

    标题中的问题"SDK does not contain 'libarclite'"指的是某个SDK缺少一个名为`libarclite`的库文件。这可能是一个错误或者是因为SDK未完整安装或配置不当导致的。 `libarclite`是一个特定的库,尤其在Android开发中...

    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...

    xcode 15 找不到libarclite 等文件

    clang: error: SDK does not contain 'libarclite' at the path '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a'; try increasing the ...

    一个跨平台的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 ...

    关于eclipse发布web项目中遇到的问题

    在发布项目时,可能会出现“Project facet Dynamic Web Module version3.0 is not supported”的错误信息。这是因为 Eclipse 工作目录下的项目文件中,org.eclipse.wst.common.project.facet.core.xml 文件中的 jst....

    Extended Backus Naur Form

    Extended Backus Naur Form (EBNF) is a formal notation used for describing the syntax of programming languages and other formal languages. It was developed as an extension of the original Backus Naur ...

    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 ...

    libarclite-arc

    Xcode 15 旧项目可能报错 SDK does not contain 'libarclite' at the path '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a';...

    数位板压力测试

    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 ...

    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 ...

    用OpenGL 导入 3DS 源文件

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

    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.-...

Global site tag (gtag.js) - Google Analytics