user3506421
user3506421

Reputation: 47

Http Status 404 error handling spring mvc

How can I implement custom http error handling in spring mvc.

For example: I have a url http://localhost:8080/demo/canvas

It display my canvas page but if the user missed the url and typed http://localhost:8080/demo/canva

It shows me Tomcat Rendered HTTP Status 404. I want it to be custom jsp page.

Upvotes: 3

Views: 955

Answers (2)

Santosh Jadi
Santosh Jadi

Reputation: 1525

Working in my application,, try this

    </web-app>  
      <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/resources/jsp/404.jsp</location>
      </error-page>
    </web-app>

Note: Make sure u restart server each time wen u make changes in web.xml

Upvotes: 1

Ravi Ranjan
Ravi Ranjan

Reputation: 740

In your web.xml you can provide a custom error page mapping based upon the error code:

<error-page>
    <error-code>404</error-code>
    <location>/PageNotFoundError.jsp</location>
</error-page>

This jsp file will be present parallel to WEB-INF folder.

Upvotes: 2

Related Questions