Page 1 of 1

Exception Handling for custom error pages

Posted: Mon Dec 03, 2012 1:30 pm
by limebot
I was looking to add custom pages for 404,500, ect.
I have added this to my web.xml file..
<error-code>404</error-code>
<location>/error/unexpected_response.html</location>
</error-page>

I check to see if it is working and it tries to load that resource but it can not file the resource:

Problem accessing /error/unexpected_response.html. Reason:

Not Found


Also in Eclipse I see:
PageNotFound - No mapping found for HTTP request with URI [/error/unexpected_response.html] in DispatcherServlet with name 'myappname'

Re: Exception Handling for custom error pages

Posted: Mon Dec 03, 2012 2:42 pm
by phillipuniverse
Looks like you do not have a controller mapping for /error/unexpected_response.html. Try adding a controller with a method that has @RequestMapping("/error/unexpected_response.html").

Re: Exception Handling for custom error pages

Posted: Tue Dec 04, 2012 11:01 am
by limebot
I am a little new at this.
I have created a new class file with this:

@Controller
public class pgErrorPage {
@RequestMapping("/error/exception.html")
public String e (HttpRequestContext request){
return "exception.html";
}

Still not working
I have tried putting the file location in templates and also tried it in the root as well.

Re: Exception Handling for custom error pages

Posted: Tue Dec 04, 2012 2:54 pm
by phillipuniverse
the pgErrorPage class (which would be in pgErrorPage.java) should go into your site src/main/java directory, under some pagackage. SO you might create a new package called 'com.mycompany.controller.error' and put 'pgErrorPage' inside of that package. You'll need to get Spring to do a component-scan of that package (I believe there is already one set up for this; search for 'component-scan' in applicationContext-servlet.xml) or reference it as a bean in some other application context xml.