System.Web.HttpException: Maximum request length e

2019-09-04 04:58发布

I am getting above exception. I have tried many solutions from SO, which didn't work, because most of them are for asp.net.

This is part of web.xml of my web app:

<servlet>
    <servlet-name>MainPageServlet</servlet-name>
    <servlet-class>servlets.MainPageServlet</servlet-class>
    <multipart-config>
        <!-- 10MB of files -->
        <max-file-size>10485760B</max-file-size>
        <!-- 10KB of form data -->
        <max-request-size>10240B</max-request-size>
        <!-- Buffer to disk over 512KB -->
        <file-size-threshold>524288B</file-size-threshold>
    </multipart-config>
</servlet>
<servlet-mapping>
    <servlet-name>MainPageServlet</servlet-name>
    <url-pattern>/mainPage/*</url-pattern>
</servlet-mapping>

This is the error I am getting(in a browser after http post file upload):

   [HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +9685979
   System.Web.HttpRequest.get_InputStream() +41
   Caucho.IIS.ResinHandler.DoHmux(HttpContext context) +138
   Caucho.IIS.ResinHandler.ProcessRequest(HttpContext context) +334
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

The file has 5,2Mb.

Any idea where should I set up the max file size? As you may see it doesn't work if I set it in the web.xml.

I am using resin java server.

Also when I add 'B' as Bytes after the size value java IDE complains. However, if it isn't there, I am getting this error:

500 Servlet exception
WEB-INF/web.xml:29: com.caucho.server.dispatch.MultipartConfigImpl.setMaxFileSize():
com.caucho.config.types.Bytes.addText(): byte-valued expression `10485760'
must have units.  '16B' for bytes, '16K' for kilobytes, '16M' for megabytes,
'16G' for gigabytes.

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-04 05:41

max-request-size is not max size of form data, it's the max size of the whole upload request.

Take a look: https://docs.oracle.com/javaee/7/tutorial/servlets011.htm 17.11.1

In your case, make max-request-size larger than 5.2MB

查看更多
登录 后发表回答