Spring MVC 中的 500 错误处理

jav*_*zif 5 java error-handling spring jsp spring-mvc

我开发我的hybris.And项目,我想在一些模板500Error.jsp ,但我不能处理500 error.Next我不能让JSP文件。

我收到此错误:

SEVERE: Servlet.service() for servlet DispatcherServlet threw exception
java.lang.NullPointerException

Aug 10, 2017 3:14:07 PM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/serverError]
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)

在 web.xml 文件中

<error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/serverError</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

在 Controller.java 以下方法中

@RequestMapping(value = "serverError", method = RequestMethod.GET)
    public String renderErrorPage(final Model model, HttpServletRequest httpRequest) throws CMSItemNotFoundException {
Run Code Online (Sandbox Code Playgroud)

Pra*_*ale 0

@java.nazif 请在 web.xml 中添加错误代码。

<error-page>
    <error-code>500</error-code>
    <location>/jsps/500Error.jsp</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)