Hi,

This what I did

1. I added below configuration

  <error-page>
        
<exception-type>java.sql.SQLException</exception-type>
                <location>/index.html</location>
        </error-page>

2. Then added below lines to my doPost()
throw new ServletException("SQLException", new SQLException());

It works for me.

Could you try to direct your error location to a static page instead of
a servlet?

Vinod

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Saturday, March 26, 2005 11:21 AM
To: tomcat-user@jakarta.apache.org
Subject: Problem with error-handling


I am using Tomcat5.5, j2sdk1.5

I deliberately created a SQLException to try error
page handling but it does not work and i don't know
why.

I have been trying to solve this problem for hours
with no result. I would appreciate it if someone
offers to look at my war file for me. I'm desperate
please help me.

web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE web-app
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN"
   "http://localhost/dtd/web-app_2_3.dtd";>
<web-app>       
        <context-param>
                <param-name>driverClassName</param-name>
                <param-value>com.mysql.jdbc.Driver</param-value>
        </context-param>
        <context-param>
                <param-name>dbUsername</param-name>
                <param-value>user</param-value>
        </context-param>
        <context-param>
                <param-name>dbPassword</param-name>
                <param-value>password</param-value>
        </context-param>
        
        <listener>
                <listener-class>
                        MyListener
                </listener-class>
        </listener>
        
        
        <servlet>
                <servlet-name>ErrorServlet</servlet-name> 
        
<servlet-class>chapter04.ErrorServlet</servlet-class>   

        </servlet>
        <servlet>
                <servlet-name>LoginServlet</servlet-name> 
        
<servlet-class>chapter04.LoginServlet</servlet-class>
                <init-param>
                        <param-name>dburl</param-name>
                
<param-value>jdbc:mysql://localhost/test</param-value>
                </init-param>
        </servlet>
        
        <servlet-mapping>
                <servlet-name>LoginServlet</servlet-name>
                <url-pattern>/login</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
                <servlet-name>ErrorServlet</servlet-name>
                <url-pattern>/error</url-pattern>
        </servlet-mapping>
        
        <error-page>
                <error-code>403</error-code>
                <location>/html/login.html</location>
        </error-page>
        
        <error-page>
        
<exception-type>java.sql.SQLException</exception-type>
                <location>/error</location>
        </error-page>
                
</web-app>


LoginServlet.java (doPost method)
public void doPost(HttpServletRequest req,
HttpServletResponse res)
                        throws IOException, ServletException {
                String userid = req.getParameter("userid");
                String password = req.getParameter("password");
                

                if (userid != null && password != null &&
userid.length() > 0
                                && password.length() > 0) {
                        
                                ServletConfig config =
getServletConfig();
                                ServletContext context =
config.getServletContext();
                                //context param
                                String driverClassName =
context.getInitParameter("driverClassName");
                                String dbUsername =
context.getInitParameter("dbUsername");
                                String dbPassword =
context.getInitParameter("dbPassword");
                                //config param
                                String dburl =
config.getInitParameter("dburl");
                                
                                MySqlDAO dao = new MySqlDAO();
                                try {
                                        dao.init(driverClassName, dburl,
dbUsername,
dbPassword);
                                } catch (ClassNotFoundException e1) {
                                        // TODO Auto-generated catch
block
                                        e1.printStackTrace();
                                        throw new
ServletException("ClassNotFoundException", e1);
                                } catch (SQLException e1) {
                                        // TODO Auto-generated catch
block
                                        e1.printStackTrace();
                                        throw new
ServletException("SQLException", e1);
                                }
                                try {
                                        if(dao.verifyUser(userid,
password)) {                            
        
context.setAttribute("userid", userid);
                                                ServletContext ct =
getServletContext();
                                                RequestDispatcher rd =
ct
        
.getRequestDispatcher("/jsp/welcome.jsp");
                                                rd.forward(req, res);
                                        } else {
        
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
                                
                                        }
                                } catch (SQLException e) {
                                        // TODO Auto-generated catch
block
                                        e.printStackTrace();
                                        throw new
ServletException("SQLException", e);
                                } catch (ServletException e) {
                                        // TODO Auto-generated catch
block
                                        e.printStackTrace();
                                } catch (IOException e) {
                                        // TODO Auto-generated catch
block
                                        e.printStackTrace();
                                }
                        
                        
                } else {
                        res.sendError(HttpServletResponse.SC_FORBIDDEN);
                        /*
                        RequestDispatcher rd =
req.getRequestDispatcher("html/login.html");
                        rd.forward(req, res);
                        */
                }
                return;
        }



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to