
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html"); PrintWriter out=response.getWriter(); HttpSession session=request.getSession(); session.setAttribute("lErrorMsg",null); String target="jsp/hrms_default.jsp"; String action=request.getParameter("action_submit"); //String actionchngpswd=request.getParameter("actionchngpswd"); //String username=request.getParameter("username"); System.out.println("user_name");
/* If the details are submitted with the user name and other fields */
System.out.println(action);
if(action.equalsIgnoreCase("hrms_user_login_submit"))
{
/* Requesting all the details from the jsp page */
System.out.println("inside action_submit");
String userId=request.getParameter("user_id");
String userName=request.getParameter("user_name");
String password=request.getParameter("user_password");
System.out.println(userId);
/* Setting the details to the bean class */
userLogin_bean obj=new userLogin_bean();
obj.setUser_Id(userId);
obj.setPassword(password);
obj.setUserName(userName);
userLogin_model modelObj=new userLogin_model();
System.out.println("model obj created");
try
{
boolean valid=modelObj.checkLogin(obj);
if(valid==true)
{
System.out.println("user valid");
target="jsp/hrms_default.jsp";
}
else
{
System.out.println("invalid user");
// String lErrorMsg="user does not exist";
//session.setAttribute("lErrorMsg",lErrorMsg);
target="jsp/Hrms_user_login.jsp";
}
//RequestDispatcher requestDispatcher=request.getRequestDispatcher(target);
//requestDispatcher.forward(request, response);
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
RequestDispatcher requestDispatcher=request.getRequestDispatcher(target);
requestDispatcher.forward(request, response);
}
} could anyone please check the code. If i enter the correct username and password it redirects me to the correct page but if I enter the incorrect username and password then it redirects me to different page

You may debug it in tomcat when the request comes to Servlet. Check for the exception also.
------------------------------------
Chandraprakash Sarathe
http://javaved.blogspot.com/

the problem is if i enter username and password correctly then it works fine and if i enter it incorrectly once it again redirects me correctly but after entering the details again after failed attempt then it does not redirect correctly.

the problem is if i enter username and password correctly then it works fine and if i enter it incorrectly once it again redirects me correctly but after entering the details again after failed attempt then it does not redirect correctly.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.