aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Unavailable Exception Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Unavailable Exception Problem" Watch "Unavailable Exception Problem" New topic
Author

Unavailable Exception Problem

Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
I was not able to get the error page indicated in the web.xml to be displayed when an unAvailableException is thrown in a servlet.
My web.xml contains:
<error-page>
<exception-type>
javax.servlet.UnavailableException
</exception-type>
<location>
/MyException.html
</location>
</error-page>
My servlet's doGet() method contains:
throw new UnavailableException("Unavailable Exception thrown");
The funny thing is that is u replace UnavailableException with ServletException in both the web.xml and the Servlet code, it works fine.
Please help!!!
Kevin Yip
Ranch Hand

Joined: Oct 17, 2000
Posts: 110
Does the doGet() throw ServletException or UnavailableException? According to your description, I think it's the former.
To make your original code to work, you may try:
doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, UnavailableException { ... }
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi Kevin,
u r right.
I didnt throw UnavailableException in my doGet() method, instead I throw ServletException.
This causes the server not to capture the ServletException because I indicate the <exception-type> in web.xml as UnavailableException.
However, when I try the following case, it didnt work:
Web.xml:
<error-page>
<exception-type>
javax.servlet.ServletException
</exception-type>
<location>
/MyException.html
</location>
</error-page>
Servlet:
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
throw new UnavailableException("My Message");
}
Please advise.
Thanks a lot.
Jim Bertorelli
Ranch Hand

Joined: Nov 28, 2001
Posts: 136
I believe, if you throw UnavailabeException and specify it in the deployment descriptor, it should work...exactly as you've mentioned in the first post. If it is not working either there some typo or there is a bug.
Try <exception-type>javax.servlet.UnavailableException</exception-type>
instead of
<exception-type>
javax.servlet.UnavailableException
</exception-type>
Kevin Yip
Ranch Hand

Joined: Oct 17, 2000
Posts: 110
On a second thought, I agreed with Jim. You original code should be fine. However, there is something particular for the UnavailableExcpetion. Here is what SRV.2.3.3.2 of the 2.3 specification said:
"If a permanent unavailability is indicated by the UnavailableException, the
servlet container must remove the servlet from service, call its destroy method,
and release the servlet instance."
If the servlet is released immediately, even before throwing out the Exception object from its doGet() method, this may explain your situation.
Jim Bertorelli
Ranch Hand

Joined: Nov 28, 2001
Posts: 136
yeah...that might be it. Try defining another exception that extends from ServletException and see if it works.
Kevin Yip
Ranch Hand

Joined: Oct 17, 2000
Posts: 110
I've tried NumberFormatException ( a subclass of java.lang.RuntimeException), java.net.MalformedURLException (a subclass of IOException), ServletException, and a subclass MyException, as defined below:

All works fine. Only UnavailableException is not working.
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi,
I have also tried MyUnavailableException (a subclass of UnavailableException) and the error page indicated in the deployment descriptor does not show. Instead, the server sends its own 503 Unavailable page.
I think that the <error-page> tag in web.xml will not work (ie. the page in <location> tag will not display) when the exception thrown in the servlet is UnavailableException or its subclass.
I have been following Java Servlet Programming book and it seems to suggest that the <exception-type> tag works for UnavailableException also. Not too sure.
Thanks a lot.
 
wood burning stoves
 
subject: Unavailable Exception Problem