aspose file tools*
The moose likes Servlets and the fly likes jsp error page from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp error page from servlet" Watch "jsp error page from servlet" New topic
Author

jsp error page from servlet

sitaram irrinki
Ranch Hand

Joined: Feb 16, 2005
Posts: 158
how to we call jsp errorpage from
servlet.
Nikhil Menon
Ranch Hand

Joined: Nov 22, 2004
Posts: 70
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

Joined: Aug 15, 2004
Posts: 2874
why calling error page. It would be called whenever error occurs, just make erorpage entry in your web.xml
Nikhil Menon
Ranch Hand

Joined: Nov 22, 2004
Posts: 70
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

Joined: Aug 15, 2004
Posts: 2874
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp error page from servlet
 
Similar Threads
how to redirect from a single servlet to more than one jsp's?
JSP to Servlet call
Attributes sent from JSP wont show in Servlet
OutputStream irritates
session variable