• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Navigating to a jsp when an exception is thrown

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 99
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic