RE: Problem with error-handling

2005-03-26 Thread bar_rin
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("");
pw.write("");
pw.write("Error Page");
pw.write("");
pw.write("");
}



--- "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 
>   
> SessionExample
>
> /servlet/SessionExample
>  
>   
>   
>
java.sql.SQLException
>   /servlet/SessionExample
>   
> 
> 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
> "" to your
>  XML element under  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
> > 
> >   
> > 
> >
>
java.sql.SQLException
> > /index.html
> > 
> > 
> > 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
> > 
> >  >PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> > Application 2.3//EN"
> >"http://localhost/dtd/web-app_2_3.dtd";>
> >
> > 
> > driverClassName
> > com.mysql.jdbc.Driver
> > 
> > 
> > dbUsername
> > user
> > 
> > 
> > dbPassword
> > password
> > 
> > 
> > 
> > 
> > MyListener
> > 
> > 
> > 
> > 
> > 
> > ErrorServlet
> > 
> >
>
chapter04.ErrorServlet
> > 
> > 
> > 
> > 
> > LoginServlet
> > 
> >
>
chapter04.LoginServlet
> > 
> > dburl
> > 
> >
>
jdbc:mysql://localhost/test
> > 
> > 
> > 
> > 
> > LoginServlet
> > /login
> > 
> > 
> > ErrorServlet
> > /error
> > 
> > 
> > 
> > 403
> > /html/login.html
> > 
> > 
> > 
> > 
> >
>
java.sql.SQLException
> > /error
> > 
> > 
> > 
> > 
> > 
> > LoginServlet.java (doPost method)
> > public void doPost(HttpServletRequest req,
> HttpServletResponse res)
> > 

RE: Problem with error-handling

2005-03-26 Thread Ramu, Vinod
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 

SessionExample
/servlet/SessionExample
 

java.sql.SQLException
/servlet/SessionExample


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 "" to your
 XML element under  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
> 
>   
>   
>
java.sql.SQLException
>   /index.html
>   
> 
> 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
> 
> PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.3//EN"
>"http://localhost/dtd/web-app_2_3.dtd";>
>  
>   
>   driverClassName
>   com.mysql.jdbc.Driver
>   
>   
>   dbUsername
>   user
>   
>   
>   dbPassword
>   password
>   
>   
>   
>   
>   MyListener
>   
>   
>   
>   
>   
>   ErrorServlet
>   
>
chapter04.ErrorServlet
> 
> 
>   
>   
>   LoginServlet
>   
>
chapter04.LoginServlet
>   
>   dburl
>   
>
jdbc:mysql://localhost/test
>   
>   
>   
>   
>   LoginServlet
>   /login
>   
>   
>   ErrorServlet
>   /error
>   
>   
>   
>   403
>   /html/login.html
>   
>   
>   
>   
>
java.sql.SQLException
>   /error
>   
>   
> 
> 
> 
> 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);
>   

RE: Problem with error-handling

2005-03-26 Thread bar_rin
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
> 
>   
>   
>
java.sql.SQLException
>   /index.html
>   
> 
> 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
>  
> PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.3//EN"
>"http://localhost/dtd/web-app_2_3.dtd";>
>  
>   
>   driverClassName
>   com.mysql.jdbc.Driver
>   
>   
>   dbUsername
>   user
>   
>   
>   dbPassword
>   password
>   
>   
>   
>   
>   MyListener
>   
>   
>   
>   
>   
>   ErrorServlet 
>   
>
chapter04.ErrorServlet
> 
> 
>   
>   
>   LoginServlet 
>   
>
chapter04.LoginServlet
>   
>   dburl
>   
>
jdbc:mysql://localhost/test
>   
>   
>   
>   
>   LoginServlet
>   /login
>   
>   
>   ErrorServlet
>   /error
>   
>   
>   
>   403
>   /html/login.html
>   
>   
>   
>   
>
java.sql.SQLException
>   /error
>   
>   
> 
> 
> 
> 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
>   

RE: Problem with error-handling

2005-03-26 Thread Ramu, Vinod
Hi,

This what I did

1. I added below configuration

  

java.sql.SQLException
/index.html


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
 
http://localhost/dtd/web-app_2_3.dtd";>
   

driverClassName
com.mysql.jdbc.Driver


dbUsername
user


dbPassword
password




MyListener





ErrorServlet 

chapter04.ErrorServlet   



LoginServlet 

chapter04.LoginServlet

dburl

jdbc:mysql://localhost/test




LoginServlet
/login


ErrorServlet
/error



403
/html/login.html




java.sql.SQLException
/error





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) {