Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc Servlet 3.0多部分配置不';无法处理最大文件大小_Spring Mvc_Servlets_Servlet 3.0_Multipartconfig - Fatal编程技术网

Spring mvc Servlet 3.0多部分配置不';无法处理最大文件大小

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

我正在使用SpringMVC构建restful服务。 当使用多部分表单服务POST请求时,我想限制发布的文件大小。 通常情况下,方法如下:

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