Hi Guys !!! I have created a Custom Exception "DataStoreException" which is being thrown by a method in a class and caught in the doGet()method of the Servlet class. On the exception occuring i would like to automatically redirect to a specified error page as mentioned within the <error-page><exception-type></exception-type></error-page><location></location> tags in web.xml. However, how should i re-throw the caught exception in the servlet since the doGet() method would then have to contain "throws DataStoreException" in its throws clause which it does'nt support(does'nt allow to overide doGet()). In this case how should the exception be thrown from the Servlet and the appropriate error page be invoked as mentioned in the <error-page> tag. Pls suggest. Thanks Guys !!!
Sun Certified Java Programmer<br />Sun Certified Web Component Developer
<error-page> <exception-type>DataStoreException</exception-type> <location>myErrorHandlingPage.jsp</location> </error-page> In your myErrorHandlingPage.jsp:
use the ServletException.getRootCause() to read the wrapped exception NOTE: Even though you are throwing ServletException from doGet(), the conainer will call the ServletException.getRootCause() to find the wrapped exception and match it your <error-page> definition. BUT, remember not to have a generic <exception-type>ServletException</exception-type> in your web.xml, because then the container will just hand over your exception to this generic's corresponding location. Hope this helps. /hs.
<blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Lance Armstrong: "What am I on? I'm on my bike, busting my ass six hours a day. What are you on?"<hr></blockquote>
Joined: Jul 16, 2002
Hi Harpartap !!! Thanks for ur reply. I have tried out the same. However, when the exception does occur it prints a stack trace of "ServletException" and below it a ROOT CAUSE Stack Trace of "DataStoreException". However, it should rather redirect to the jsp page specified in the web.xml file. This application is currently being run on tomcat 3.2.1. What needs to be done ??? Pls suggest. Thanks Harpartap
I seem to have the same problem. I am using Websphere Application Single Server 4.0. I have placed a IllegalArgumentException in the doPost method and configured an error page for it in web.xml. This works fine. But when i try: <CODE> AppException e = new AppException("Error", this.getClass().getName()); throw new ServletException("Servlet POST error.", e); </CODE> and: <CODE> <error-page id="ExceptionTypeErrorPage_1"> <exception-type>com.company.AppException</exception-type> <location>/jsp/error.jsp</location> </error-page> </CODE> I get a white screen with: Servlet POST error. Of course, this is not the content of error.jsp
"...you've got to ask yourself one question, Do I feel lucky?"
Kees van Oosterhout
Joined: Jul 08, 2002
Ok. It works fine now. You should check if the location in web.xml. First try to redirect the exception to jsp page with only HTML tags. If this works set the jsp page as an error page with: <%@ page isErrorPage="true" %> And cast the exception object to an ServletException. The root cause of this exception is your DataStoreException. (on IBM Websphere) Hope it helps....