aspose file tools*
The moose likes Servlets and the fly likes Redirect internal server error to custom JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Redirect internal server error to custom JSP" Watch "Redirect internal server error to custom JSP" New topic
Author

Redirect internal server error to custom JSP

Manigandan Velraj
Greenhorn

Joined: Nov 30, 2009
Posts: 14
Hi,

I have J2EE application(I am using Struts2 / EJB3.0). I have used the below code in web.xml to catch the 500 error,


If 500 error is caused by my JSP (meaning i missed some tags/ some error in jsp) i am redirected to my custom error page. But if there is some error in my action / network time out / null pointer exception i am not redirected to my custom error page instead i get HTTP INTERNAL SERVER ERROR.

Please let me know if i have to any other configuration in web.xml for me to get redirected to my custom error page.

Thanks in advance.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

For handling exceptions, you should use the <exception-type> within the <error-page> element.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Manigandan Velraj
Greenhorn

Joined: Nov 30, 2009
Posts: 14
Thanks for your reply,

Can you please post a sample web.xml containing the exception handling.

Thanks.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

Simply specify the exception class name for the <exception-type> element.

For handling all of the exceptions, use java.lang.Throwable as the exception type.
Manigandan Velraj
Greenhorn

Joined: Nov 30, 2009
Posts: 14
Hi,

Thanks for the info.. This was helpful. If i use java.lang.Throwable will i be able to catch the network timeout / response time outs.

Also can you please let me know the advantage of using java.lang.Throwable instead of java.lang.Exception.

Thanks in advance.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

If you use java.lang.Throwable instead of java.lang.Exception, it can handle all of the exceptions, and 5xx errors (but not 4xx errors). For handling 4xx errors, you should use separate error-page declaration with proper error-code specifications.

Devaka
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirect internal server error to custom JSP
 
Similar Threads
Axis2 and RAD 6.0 (details)
Custom error messages per application
error page under WEB-INF
JSP and custom Exception class
Exception Handling