This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirect internal server error to custom JSP

 
Manigandan Velraj
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For handling exceptions, you should use the <exception-type> within the <error-page> element.
 
Manigandan Velraj
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply,

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

Thanks.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic