谁能告诉我如何在登录方法中使用会话?在这里我的日志代码及其正常工作。需要为此设置会话并且不知道如何..
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String operation = request.getParameter("operation");
if(operation!=null && operation.equalsIgnoreCase("login")){
loginDetail(request,response);
}//else if(operation!=null && operation.equalsIgnoreCase("login")){
//logout(request,response);
//}
}
private void loginDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
User u = new User();
UserService us =new UserServiceImpl() ;
String Uname = request.getParameter("txtUname");
String Pwrd = request.getParameter("txtPwrd");
u.setUname(Uname);
u.setPwrd(Pwrd);
System.out.println(Uname+""+Pwrd);
try {
if(us.Userlogin(u.getUname(),u.getPwrd())){
String message = "Thank you, " + Uname +"..You are now logged into the system";
HttpSession session = request.getSession(true);
session.setAttribute("username", Uname);
session.setAttribute("password", Pwrd);
response.setContentType("text/html");
request.setAttribute("message", message);
request.getRequestDispatcher("/Menu.jsp").forward(request, response);
}else {
String message = "You have to register first or check Your user name password again!";
request.setAttribute("loginMsg", message);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/Login.jsp");
rd.forward(request, response);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我只是在“if(us.Userlogin(u.getUname(),u.getPwrd()))”语句中放了几行代码..引导我完成这段代码