You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Carlos Bracho <ca...@gmail.com> on 2005/07/04 13:37:23 UTC

Handling exceptions declaratively

Hello everybody.

I am trying to handling exceptions declaratively, here is part of my the 
web.xml file:


<error-page>

<exception-type>ladw.model.UserNotFoundException</exception-type>

<location>/error.jsp</location>

</error-page>

<error-page>

<exception-type>ladw.model.IlegalAccessException</exception-type>

<location>/error.jsp</location>

</error-page>

<error-page>

<exception-type>ladw.model.InvalidFileNameException</exception-type>

<location>/error.jsp</location>

</error-page> 

<servlet>

<servlet-name>testServlet</servlet-name>

<servlet-class>ladw.controller.testServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>testServlet</servlet-name>

<url-pattern>/testServlet</url-pattern>

</servlet-mapping>


I created a test servlet with the following code:


/*

* testServlet.java

*

* Created on 3 de julio de 2005, 03:17 PM

*/

 package ladw.controller;


import java.io.*;

import java.net.*;

import ladw.model.UserNotFoundException;

import javax.servlet.*;

import javax.servlet.http.*;

 public class testServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse 
response)

throws ServletException, IOException {

throw new ServletException("Wrapped UserNotFoundException",new 
UserNotFoundException()); 

}

protected void doPost(HttpServletRequest request, HttpServletResponse 
response)

throws ServletException, IOException {

 }
 
}

 When I write this urL http://localhost:8080/LADW/testServlet in my browser 
I got the follow error:

 ladw.model.UserNotFoundException: User does not exist

ladw.controller.testServlet.doGet(testServlet.java:28)

javax.servlet.http.HttpServlet.service(HttpServlet.java:697)

javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(
MonitorFilter.java:362)

 What is wrong in the error pages declaration??? why the error page does not 
appear?

-- 
------------------------------------------------------------------
Carlos J, Bracho M. 
------------------------------------------------------------------
e-mail: carlos.bracho@gmail.com
MSN: cbrachomi@hotmail.com
+58 416 409 21 75 
------------------------------------------------------------------