【问题标题】:How to avoid stacktrace HTTP Status 500 page with MaxUploadSizeExceededException如何使用 MaxUploadSizeExceededException 避免堆栈跟踪 HTTP 状态 500 页面
【发布时间】:2011-07-02 16:41:17
【问题描述】:

我有这段代码(就像在 Spring 的参考中一样):

<bean id="multipartResolver" 
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="100000"/>
</bean>

当用户尝试上传超过 100 kB 的文件时,将显示 HTTP 状态为 500 的服务器错误页面和堆栈跟踪。如何以最简单的方式避免这种情况?我想重定向到表单页面并显示我自己的错误消息。

【问题讨论】:

    标签: java spring servlets file-upload spring-mvc


    【解决方案1】:

    假设是org.springframework.web.multipart.MaxUploadSizeExceededException,只需在web.xml中定义一个error-page,如下:

    <error-page>
        <exception-type>org.springframework.web.multipart.MaxUploadSizeExceededException</exception-type>
        <location>/upload-error.jsp</location>
    </error-page>
    

    请注意,这仅在您没有另一个覆盖 ServletException 或其超类之一的 &lt;error-page&gt; 时才有效。否则,您必须引入一些异常过滤器来解开并重新抛出ServletException 的根本原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-14
      • 2012-06-30
      • 1970-01-01
      • 2010-09-12
      • 2014-04-17
      • 2013-05-30
      • 2011-12-29
      • 2011-05-25
      相关资源
      最近更新 更多