How to create Custom 404 page in Web Application

Points To Remember

You can define your custom error pages in web.xml. This is the best way to define custom 404 and other error pages.

Configure Custom error pages

Many times we want to create custom error pages in our web applications like for a 404 error, resource not found, 500 internal server error and other errors that we see commonly. So we may want to redirect such errors to a better looking custom error page.

If you want to redirect to custom error pages in a web application you can add these custom error pages in web.xml like following.

web.xml
 <error-page>
  <error-code>400</error-code>
  <location>/error/400.html</location>
 </error-page>
 
 <error-page>
  <error-code>404</error-code>
  <location>/error/404.html</location>
 </error-page>
 
 <error-page>
  <error-code>500</error-code>
  <location>/error/500.html</location>
 </error-page>
 
 <error-page>
  <error-code>503</error-code>
  <location>/error/503.html</location>
 </error-page>
 
You can define your error page location in the <location> tag.

No comments :

Post a Comment