• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp error page from servlet

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to we call jsp errorpage from
servlet.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sitaram,

To call Jsp Error page from servlet you need to do a trick.
First of all we should know If the source of the exception was a JSP page, the Web container also stores the exception as a request attribute called "javax.servlet.jsp.jspException"

So if you want from Servlet to JSP-Error-Page then you have to set the exception in the same way as the Web Container does ie in the catch block you set : request.setAttribute("javax.servlet.jsp.jspException");
then use RequestDispatcher to forwrd to your error page



Remeber: You will get an IllegalStateException if you had opened OutputStream or PrintStream before forwarding
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why calling error page. It would be called whenever error occurs, just make erorpage entry in your web.xml
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As my understanding about this is,

If you use <error-page> element of web.xml to divert to error pages, all the jsp/servlets that gets that exception will be directed to the same error page.

If you do it the way as mentioned in the above Post(by using RequestDispatcher), you can have corresponding error page for some jsp/servlet. (for jsp you could use page directive attribute errorPage=" "). So that these error pages to which request get diverted show more specific information.

I think that is what sitaram irrinki wanted. Please correct me if i am wrong.

Nikhil
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nikhil Menon:
So that these error pages to which request get diverted show more specific information.



Well, i think we can just show more specific message there on general error page.
 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic