• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp error page from servlet

 
sitaram irrinki
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to we call jsp errorpage from
servlet.
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic