I found out what is wrong. I should set the response
header to OK. Then the error page will display
correctly.

ErrorServlet:

public void doPost(HttpServletRequest req,
HttpServletResponse res) throws IOException,
ServletException {
---->           res.setStatus(HttpServletResponse.SC_ACCEPTED);
                PrintWriter pw = res.getWriter();
                pw.write("<head>");
                pw.write("<title>");
                pw.write("Error Page");
                pw.write("</title>");
                pw.write("</head>");
        }



--- "Ramu, Vinod" <[EMAIL PROTECTED]> wrote:

> Yeah, I agree with you .......I should and it
> works!!!!
> 
> To check our understanding this what I did this
> time. I updated my
> configuration to 
>       <servlet-mapping>
>         <servlet-name>SessionExample</servlet-name>
>        
> <url-pattern>/servlet/SessionExample</url-pattern>
>      </servlet-mapping>
>       <error-page>
>       
>
<exception-type>java.sql.SQLException</exception-type>
>               <location>/servlet/SessionExample</location>
>       </error-page>
> 
> As you can see now it's redirected to a servlet.
> 
> Could you try some thing like this
> 
> 1. try a new servlet, which is very simple.
> 2. test this servlet by entering it's URL in your
> browser.
> 3. if this servlet is working fine then map it's
> "<url-pattern>" to your
> <location> XML element under <error-page> as shown
> in the above sample.
> 
> I hope this should work. It worked for me (I tried
> this on
> jakarta-tomcat-5.5.4)
> 
> Vinod
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, March 26, 2005 8:17 PM
> To: Tomcat Users List
> Subject: RE: Problem with error-handling
> 
> 
> yeah it works. But i still cannot understand why my
> code does not work. Theoretically my code should
> work
> right? 
> --- "Ramu, Vinod" <[EMAIL PROTECTED]> wrote:
> 
> > 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: [email protected]
> > 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();
> 
=== message truncated ===



                
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 

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

Reply via email to