Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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
Java 如何使用MaxUploadSizeExceedeException避免stacktrace HTTP状态500页面_Java_Spring_Servlets_File Upload_Spring Mvc - Fatal编程技术网

Java 如何使用MaxUploadSizeExceedeException避免stacktrace HTTP状态500页面

Java 如何使用MaxUploadSizeExceedeException避免stacktrace HTTP状态500页面,java,spring,servlets,file-upload,spring-mvc,Java,Spring,Servlets,File Upload,Spring Mvc,我有以下代码(如Spring的参考中所示): 当用户试图上传超过100KB的文件时,将显示HTTP状态为500和stacktrace的服务器错误页面。如何以最简单的方式避免这种情况?我想重定向到表单页面并显示我自己的错误消息。假设它是org.springframework.web.multipart.maxuploadSizeExceedeException,只需在web.xml中定义错误页面,如下所示: <error-page> <exception-type&g

我有以下代码(如Spring的参考中所示):



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

假设它是
org.springframework.web.multipart.maxuploadSizeExceedeException
,只需在
web.xml
中定义
错误页面
,如下所示:

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

org.springframework.web.multipart.maxUploadSizeExceedeException
/upload-error.jsp
请注意,这仅在您没有另一个涵盖
ServletException
或其超类的
时有效。否则,您必须引入一些异常过滤器,它可以打开并重新调用
ServletException
的根本原因

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