【问题标题】:FileUploadBase$SizeLimitExceededException apache tomcatFileUploadBase$SizeLimitExceededException apache tomcat
【发布时间】:2014-11-04 15:59:25
【问题描述】:

我尝试从 JSP 文件上传文件,但在 catalina.out 中出现以下错误。正如许多博客中所述,我增加了 webapps/manager/WEB-INF/web.xml 下的 max-file-size 但我仍然遇到同样的问题...我应该在哪里增加它来解决这个错误?

<multipart-config>
      <!-- 50MB max -->
      <max-file-size>5242880000000</max-file-size>
      <max-request-size>5242880000000</max-request-size>
      <file-size-threshold>0</file-size-threshold>
    </multipart-config>

org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (341297) exceeds the configured maximum (51200)

【问题讨论】:

    标签: tomcat tomcat7


    【解决方案1】:

    这是在 web.xml 中为经理应用配置的。

    例如:

      <servlet>
        <servlet-name>HTMLManager</servlet-name>
        <servlet-class>org.apache.catalina.manager.HTMLManagerServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>2</param-value>
        </init-param>
        <multipart-config>
          <!-- 50MB max -->
          <max-file-size>52428800</max-file-size>
          <max-request-size>52428800</max-request-size>
          <file-size-threshold>0</file-size-threshold>
        </multipart-config>
      </servlet>
    

    https://github.com/apache/tomcat/blob/7.0.x/webapps/manager/WEB-INF/web.xml#L56-L57

    管理器应用使用 Servlet 3.0 API。如果您直接使用公用文件上传,则由您自己决定,您需要手动配置。

    【讨论】:

    • 找到 webapps/manager/WEB-INF/web.xml,将 max-file-sizemax-request-size 编辑为您需要的任何内容。
    • 网址已损坏
    • 固定网址。谢谢
    • webapps/manager 不存在时怎么办?
    • 这个问题是针对 Tomcat 附带的 Manager 应用程序提出的,因此说明是在 web.xml 中为 manager 应用程序更新最大允许大小。如果您在其他应用中看到此问题,请为您的应用调整 web.xml。如果您没有 web.xml,请参阅stackoverflow.com/a/65473679/1585136
    【解决方案2】:

    我遇到了同样的问题。我通过在位于&lt;tomcat-root-folder&gt;/conf/server.xml 的http 服务器tomcat 连接器中设置参数maxPostSize 来解决它,如下所示:

    <Connector connectionTimeout="20000" 
               port="8080" 
               protocol="HTTP/1.1" 
               redirectPort="8443" 
               maxPostSize="52428800" />
    

    maxPostSize 设置为52428800 将上传文件大小增加到50 MB。默认设置为2 MB

    更多解释,请阅读:https://tomcat.apache.org/tomcat-7.0-doc/config/http.html

    【讨论】:

      【解决方案3】:

      https://maxrohde.com/2011/04/27/large-war-file-cannot-be-deployed-in-tomcat-7/

      转到管理器应用程序的 web.xml(例如,它可能位于 /tomcat7/webapps/manager/WEB-INF/web.xml 下。 增加 max-file-size 和 max-request-size:

      <multipart-config>
      <!– 50MB max –>
      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>
      <file-size-threshold>0</file-size-threshold>
      </multipart-config>
      

      【讨论】:

        【解决方案4】:

        你可以像下面这样在 Servlet 中使用

            @WebServlet(name = "RemittanceDocApi", urlPatterns = {"/RemittanceDocApi"})
            @MultipartConfig(fileSizeThreshold = 1024 * 1024 * 2, // 2MB
            maxFileSize = 1024 * 1024 * 10, // 10MB
            maxRequestSize = 1024 * 1024 * 50)   // 50MB
            public class RemittanceDocApi extends HttpServlet {
        
            }
        

        【讨论】:

          【解决方案5】:

          如果您使用的是Spring MultipartResolver,请找到该 bean 并更改它的 maxUploadSize 属性。

          `<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
             <property name="maxUploadSize" value="52428800" />
           </bean>`
          

          给定代码将上传文件大小设置为50 MB

          【讨论】:

            猜你喜欢
            • 2014-06-19
            • 1970-01-01
            • 1970-01-01
            • 2013-11-26
            • 1970-01-01
            • 1970-01-01
            • 2012-02-19
            • 2012-08-22
            • 2011-03-21
            相关资源
            最近更新 更多