6

I developed my project with hybris.And I want to some template in 500Error.jsp but I can't handle 500 error.Next I can't get jsp file.

I got this error:

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

in web.xml file

<error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/serverError</location>
</error-page>

in Controller.java following method

@RequestMapping(value = "serverError", method = RequestMethod.GET)
    public String renderErrorPage(final Model model, HttpServletRequest httpRequest) throws CMSItemNotFoundException {
atakb
  • 3
  • 3
java.nazif
  • 713
  • 1
  • 9
  • 18

3 Answers3

3

You need to use a @ControllerAdvice like the example below:

@ControllerAdvice
public class ControllerExceptionHandler {

  private static Logger log = LoggerFactory.getLogger(ControllerExceptionHandler.class);

  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  @ExceptionHandler(Exception.class)
  public void notFoundHandler() {
    log.debug("Item not found. HTTP 500 returned.");
  }

}
José Mendes
  • 950
  • 2
  • 14
  • 30
1

Can you put a breakpoint in your error controller and it stops as expected? If not, you can try to make a exception handler and then forward message to your controller.

@ExceptionHandler(Exception.class)
public String handleException(final Exception e) {

    return "forward:/serverError";
}
staszko032
  • 802
  • 6
  • 16
0

@java.nazif please add error-code in web.xml.

<error-page>
    <error-code>500</error-code>
    <location>/jsps/500Error.jsp</location>
</error-page>
Pravin Abhale
  • 395
  • 2
  • 4
  • 15
  • Thank you very much @Pravin Abhale.I tried this solution but it is not enough for issue.Because I want /jsps/500Error.jsp not go to directly jsp file .It must go in controller and in requestMapping() – java.nazif Aug 10 '17 at 13:37