Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Navigating to a jsp when an exception is thrown  RSS feed

 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused about a scenario

I need to navigate/render a jsp when a custom exception is thrown from a code block in my app.

for that in web.xml I have configured the error handling


Code block


My questions are:

Is this the correct way to invoke a jsp when my code throws an exception?
Do I need a try catch block to handle the thrown RecordNotFoundException, if yes how would I navigate to the jsp from the catch block?
 
Mauro Trevigno
Ranch Hand
Posts: 99
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should add the following to your JSP error page:

isErrorPage="true"



test1.jsp
<%@page isErrorPage=”false” errorPage=”error.jsp” %>

*****

test2.jsp
<%@page isErrorPage=”false” errorPage=”error.jsp” %>

*****

error.jsp
<%@page isErrorPage=”true”%>

<h2>Exception:</h2>
${pageContext.exception}

<h2>Status code:</h2>
${pageContext.errorData.statusCode}

isErrorPage = true, you can use the Exception object in JSP.


Tutorial JSP Exceptions

Regards,
-M
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I never display a JSP page directly. I configure the deployment descriptor to activate a servlet that figures out what should happen, including logging, and forwarding to an appropriate JSP.

And no, you do not catch exceptions that you want the deployment descriptor to handle.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!