
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);
}
}
in the above code if i enter a valid username and password i am redirected to the correct page but if i enter an invalid details at the first attempt i am redirected to the correct page but after that if i again try to login using either the correct or incorrect details i am not directed to the proper page.. please help....
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.