对于无法解析多部分servlet请求,嵌套异常为org.apache.commons.fileupload.FileUploadException感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于
对于无法解析多部分servlet请求,嵌套异常为org.apache.commons.fileupload.FileUploadException感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于Apache Commons FileUpload 1.3.1 发布、Apache Commons FileUpload 1.3.2 发布、Apache Commons FileUpload 1.3.3 发布、Apache Commons-FileUpload 1.3 发布的有用信息。
本文目录一览:- 无法解析多部分servlet请求,嵌套异常为org.apache.commons.fileupload.FileUploadException
- Apache Commons FileUpload 1.3.1 发布
- Apache Commons FileUpload 1.3.2 发布
- Apache Commons FileUpload 1.3.3 发布
- Apache Commons-FileUpload 1.3 发布
无法解析多部分servlet请求,嵌套异常为org.apache.commons.fileupload.FileUploadException
通过使用CommonsMultipartResolver库在Spring中上传10 MB大小的csv文件时遇到错误。我已经在xml文件Xml File
Confi中进行了以下设置:
<beans:bean id="multipartResolver"><!-- max upload size in bytes --><beans:property name="maxUploadSize" value="99971520" /> <!-- 99MB --><!-- max size of file in memory (in bytes) --><beans:property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
控制器代码:
@RequestMapping(value="/uploadForm",method = RequestMethod.POST)public @ResponseBody String uploadForm1(@ModelAttribute("admin") BillingAndRecon billingandrecon,@RequestParam String id,BindingResult result,Principal principal,@RequestParam MultipartFile file,HttpSession session) throws ServiceException, DaoException, IllegalStateException, IOException { File uploadFile = null; String msg = ""; if (!file.getOriginalFilename().equals("")) { logger.info("Before Multipart file get path >> "); BillingAndReconServiceImpl asi = (BillingAndReconServiceImpl) this.billingAndReconService;// not correct!! String uploadDirectoryPath = asi.getUploadDirectoryPath(); // not correct!! uploadFile = new File( uploadDirectoryPath + file.getOriginalFilename()); logger.info("Before Multipart file get path uploadDirectoryPath >> "+uploadDirectoryPath); file.transferTo(uploadFile); }}
表单页面:
<form:form action="./uploadForm" method="post" enctype="multipart/form-data" ModelAttribute=="admin"> <input type="file" name="file" /> <input type="text" name="id" /> </form:form>
但是我不明白什么是问题。我也尝试设置大小和设置标头enctype="multipart/form-data"
,但尚未解决。
以下是错误:
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found] with root cause org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was foundat org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:954)at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:156)at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:139)at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1047)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:892)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827)at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)at java.lang.Thread.run(Thread.java:744)
答案1
小编典典正如 @ChristianMaioliM 在评论中所要求的那样,添加了有关以下内容的更多详细信息:代码中的问题是
BindingResult参数未遵循模型对象 。
Errors或BindingResult参数必须跟随立即绑定的模型对象,因为方法签名可能具有多个模型对象,并且Spring将为它们中的每个对象创建一个单独的BindingResult实例,因此以下示例将不起作用
参考docs
BindingResult和@ModelAttribute的无效顺序
要解决此问题,请更改您的控制器方法处理程序签名,以遵循BindingResult和模型对象之间的参数顺序,例如:
从:
@RequestMapping(value="/uploadForm",method = RequestMethod.POST)public @ResponseBody String uploadForm1(@ModelAttribute("admin") BillingAndRecon billingandrecon,@RequestParam String id,BindingResult result,Principal principal,@RequestParam MultipartFile file,HttpSession session) throws ServiceException, DaoException, IllegalStateException, IOException {
至:
@RequestMapping(value="/uploadForm",method = RequestMethod.POST)public String uploadForm1( @ModelAttribute("admin") BillingAndRecon billingandrecon, BindingResult result, Principal principal, HttpSession session) throws ServiceException, DaoException, IllegalStateException, IOException { //do file save here return "some-view-name";}
并在BillingAndRecon类中添加mulitpart / binding字段,例如:
public class BillingAndRecon { private MultipartFile file; private String id; no-arg constructor; getters; setters;}
注意: BindingResult参数应在@ModelAttrubiute/@RequestBody
和jsp形式:
<form:form action="${pageContext.request.contextPath}/uploadForm" method="post" enctype="multipart/form-data" modelAttribute="admin"> <input type="file" name="file" /> <form:input path="id" /></form:form>
并且不要忘记在GET处理程序中添加绑定实例,例如:
@RequestMapping(value="/uploadForm",method = RequestMethod.GET)public String uploadFormView(Model model){ model.addAttribute("admin", new BillingAndRecon()); return "your-upload-view-name";}
Apache Commons FileUpload 1.3.1 发布
Apache Commons FileUpload 1.3.1 发布,这是一个安全补丁版本,修复了编号为 CVE-2014-0050 的一个 DoS 安全漏洞。
下载地址:http://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi
Apache Commons FileUpload 1.3.2 发布
Apache Commons FileUpload 1.3.2 发布了。
Apache Commons FileUpload 使用最为广泛的Java文件上传组件,Struts本身采用这个包来处理文件上传。文档非常详细、简单易用。
下载地址:点击此处
详情:http://commons.apache.org/proper/commons-fileupload/
Apache Commons FileUpload 1.3.3 发布
Apache Commons FileUpload 1.3.3 已发布。
Apache Commons FileUpload 库解析符合 RFC 1867 (HTML 中基于表单的文件上传)的 HTTP 请求。也就是说,如果使用 POST 方法提交了 HTTP 请求,并且内容类型为 “multipart / form-data”,则 FileUpload 可以解析该请求,并以调用者轻松使用的方式使结果可用。
此版本唯一的更改是:
FILEUPLOAD-279:为了安全起见,DiskFileItem 不能再反序列化,除非设置了特定的系统属性。
发行说明
下载地址:
http://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi
>>>【评论有礼】6月6日-30日评论每日更新的“新闻资讯和软件更新资讯”,评论点赞数超过 20 的可登上每周更新的“源资讯”和“软件周刊”两大栏目,点赞数超过 50 的还将获得 5 活跃积分奖励和开源中国定制好礼。详情
Apache Commons-FileUpload 1.3 发布
Apache 的文件上传组件 commons-fileupload 今天发布了 1.3 版本,该版本修复了一个重要的安全问题:
SECURITY - CVE-2013-0248, see http://seclists.org/fulldisclosure/2013/Mar/76
其他改进内容还包括:
Bug
=============
* [FILEUPLOAD-143] - "Stream ended unexpectedly" when posting from a
Flash client
* [FILEUPLOAD-173] - Manifest for OSGi has invalid syntax
* [FILEUPLOAD-183] - commons-io dependency does not get loaded by
maven if only dependency to commons-fileupload is specified
* [FILEUPLOAD-185] - http://commons.apache.org/fileupload/index.html
is out of date
* [FILEUPLOAD-186] - http://commons.apache.org/fileupload/index.html
should not mention nightly builds
* [FILEUPLOAD-189] - DiskFileItemFactory use of FileCleaningTracker
is documented or coded wrong
* [FILEUPLOAD-195] - Error reading the file size larger than 2 gb
* [FILEUPLOAD-197] - ServletFileUpload isMultipartContent method does
not support HTTP PUT
* [FILEUPLOAD-199] - Uploads have unexpected results for files with
non-ASCII names - support RFC2047
* [FILEUPLOAD-202] -
org.apache.commons.fileupload.FileUploadBase$IOFileUploadException:
Processing of multipart/form-data request failed. Stream ended
unexpectedly
* [FILEUPLOAD-204] - FileItem.getHeaders() returns always null.
* [FILEUPLOAD-212] - Insecure request size checking
* [FILEUPLOAD-214] - ServletFileUpload only accepts POST requests
* [FILEUPLOAD-228] - (Servlet|Portlet)RequestContext#contentLength()
must return request.getContentLength() if Content-length header is not
available
* [FILEUPLOAD-229] - toLowerCase() is Locale-dependent; should use
toLowerCase(Locale.ENGLISH) instead
* [FILEUPLOAD-232] - There are no unit tests for the new utils.mime classes
Improvement
=============
* [FILEUPLOAD-182] - Documentation: add simple HTML form example to
fileupload user guide
* [FILEUPLOAD-207] - enhance file read/write performance
* [FILEUPLOAD-209] - Add Support for Generic Types
* [FILEUPLOAD-210] - Process HTTP Requests Into Maps
* [FILEUPLOAD-223] - Update commons-io dependency to latest version
that supports JDK1.5
* [FILEUPLOAD-224] - Avoid string concatenations while parsing
headers, use buffers instead
* [FILEUPLOAD-225] - Replace java.rmi.server.UID() with java.util.UUID
* [FILEUPLOAD-226] - DiskFileItem.counter could be converted to
AtomicInteger (or AtomicLong?)
* [FILEUPLOAD-227] - Private immutable fields which could be final
Task
=============
* [FILEUPLOAD-201] - Update to JDK 1.5 and bump IO dependency to 2.X
* [FILEUPLOAD-215] - version 1.3 improvement tasks
Sub-task
=============
* [FILEUPLOAD-216] - Update the project tree dirs according to
default Maven conventions
* [FILEUPLOAD-217] - drop JDK1.3 support and update to Java5
* [FILEUPLOAD-218] - Update version in POM
* [FILEUPLOAD-219] - upgrade tests to JUnit 4
* [FILEUPLOAD-220] - replace package.html with package-info.java
* [FILEUPLOAD-221] - FileItemHeadersImpl can now use LinkedHashMap
* [FILEUPLOAD-222] - Mark @deprecated classes/methods with
@Deprecated annotation
* [FILEUPLOAD-233] - Base64Decoder doesn''t correctly implement RFC 4648
今天关于无法解析多部分servlet请求,嵌套异常为org.apache.commons.fileupload.FileUploadException的分享就到这里,希望大家有所收获,若想了解更多关于Apache Commons FileUpload 1.3.1 发布、Apache Commons FileUpload 1.3.2 发布、Apache Commons FileUpload 1.3.3 发布、Apache Commons-FileUpload 1.3 发布等相关知识,可以在本站进行查询。
本文标签: