2011-02-23 111 views
2

我有这样的代码(如在Spring的参考):如何避免堆栈跟踪HTTP状态500页面MaxUploadSizeExceededException

<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和堆栈跟踪会被显示。如何以最简单的方式避免这种情况?我想重定向到表单页面并显示我自己的错误消息。

回答

2

假设它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> 

注意,这只能在你没有其他<error-page>覆盖ServletException或其超之一。否则,你必须引入一些异常过滤器,它会解开并重新引发ServletException的根本原因。