Problem with req.getRequestDispatcher

Joined
Sep 13, 2009
Messages
1
Reaction score
0
I have made a index.html file, in which there is option to fill username and password and role(Operator or Administrator).

When we submit this, it goes to login servlet. and if credentials are correct is should redirects to operator.jsp ( If role = operator)..

But it is unable to find this jsp file.

I have put the jsp file in ...\Apache Group\Tomcat 4.1\webapps\ROOT\studio

folder...

I dnt knw y it is unalble to find that file. Please help.

I am also posting Login Servlet code snippet:




public class login extends HttpServlet{

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out=res.getWriter();
String n=req.getParameter("user");
String p=req.getParameter("pass");
String r=req.getParameter("role");

RequestDispatcher rd=null;
if(n==""||p==""){

rd=req.getRequestDispatcher("studio/index.html");
rd.include(req,res);
out.println("Password Or User Name can't be empty");
}
else
{
Connection con=null;
Connection con1=null;
PreparedStatement pstm=null;
ResultSet rt=null;

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:eek:dbc:studio");
}catch(Exception er){
}


try{
pstm=con.prepareStatement("select * from login where name=? and password=? and role=?");

pstm.setString(1,n);
pstm.setString(2,p);
pstm.setString(3,r);

rt=pstm.executeQuery();

System.out.println("query Fired");
if(rt.next()==true){

try{
con1=DriverManager.getConnection("jdbc:eek:dbc:studio");
PreparedStatement pstm2=con1.prepareStatement("insert into log (userid,ipadd,logindatetime) values(?,?,?)");
pstm2.setString(1,n);
pstm2.setString(2,req.getRemoteAddr());
Date d=new Date();
pstm2.setString(3,d.toString());
System.out.println("query set");
pstm2.executeUpdate();
pstm2.close();
}catch(Exception e){System.out.println("Error in PS "+e.getMessage());}
System.out.println("values inserted");


if(r.equalsIgnoreCase("Operator")){
rd=req.getRequestDispatcher("operator.jsp");

HttpSession ses=req.getSession(true);
ses.setAttribute("conn",con);
ses.setAttribute("uname",n);

rd.forward(req,res);

}
else
if(r.equalsIgnoreCase("Administrator")){
rd=req.getRequestDispatcher("studio/admin.jsp");

HttpSession ses=req.getSession(true);
ses.setAttribute("conn",con);
ses.setAttribute("uname",n);
rd.forward(req,res);
System.out.println("Administrator passed");
}
rt.close();


pstm.close();




}
else{
rd=req.getRequestDispatcher("studio/index.html");
out.print(" UserName Or Password Invalid");
rd.include(req,res);

}


}catch(SQLException e){}
}

}

}


Please help in this regard...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top