

Table of Contents
ErrorController.java
package com.springdemo; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/") public class ErrorController { @RequestMapping(value = "404",method = RequestMethod.GET) public String Page404(ModelMap model) { return "404"; } @RequestMapping(value = "500",method = RequestMethod.GET) public String Page500(ModelMap model) { return "500"; } }
web.xml
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Spring MVC Application</display-name> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <error-page> <error-code>404</error-code> <location>/404</location> </error-page> <error-page> <error-code>500</error-code> <location>/500</location> </error-page> </web-app>
404.jsp
<html> <body> <h1>This is javadeveloperzone.com custom 404 page.</h1> </body> </html>
500.jsp
<html> <body> <h1>This is javadeveloperzone.com custom 500 page.</h1> </body> </html>
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.