Spring mvc Servlet 3.0多部分配置不';无法处理最大文件大小
我正在使用SpringMVC构建restful服务。 当使用多部分表单服务POST请求时,我想限制发布的文件大小。 通常情况下,方法如下:Spring mvc Servlet 3.0多部分配置不';无法处理最大文件大小,spring-mvc,servlets,servlet-3.0,multipartconfig,Spring Mvc,Servlets,Servlet 3.0,Multipartconfig,我正在使用SpringMVC构建restful服务。 当使用多部分表单服务POST请求时,我想限制发布的文件大小。 通常情况下,方法如下: <web-app version="3.0"... //...other code omitted <servlet> <servlet-name>restful</servlet-name> <servlet-class>org.springframework.web.servlet
<web-app version="3.0"...
//...other code omitted
<servlet>
<servlet-name>restful</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/restful-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<multipart-config>
<max-file-size>500</max-file-size>
</multipart-config>
</servlet>
它成功了!!!
那么,为什么web.xml方式不起作用呢?等待您的回答。我认为最大文件大小以字节为单位,您必须将500乘以1024*1024,如下所示
<multipart-config>
<max-file-size>524288000</max-file-size>
<max-request-size>524288000</max-request-size>
</multipart-config>
@MultipartConfig(location="/tmp", fileSizeThreshold=1024*1024,
maxFileSize=1024*1024*5, maxRequestSize=1024*1024*5*5)
您需要最大文件大小和最大请求大小以及文件大小阈值
<multipart-config>
<max-file-size>500</max-file-size>
<max-request-size>700</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
500
700
0
你在哪里托管了应用程序,可能它不是Servlet 3+容器?@BijuKunjummen我使用的是STS内置的Pivotal tc服务器,它应该使用嵌入式tomcat 8.0.9
@MultipartConfig(location="/tmp", fileSizeThreshold=1024*1024,
maxFileSize=1024*1024*5, maxRequestSize=1024*1024*5*5)
<multipart-config>
<max-file-size>500</max-file-size>
<max-request-size>700</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>