Z02登陸ACTION

public class LoginAction extends Action {

 public ActionForward execute(ActionMapping mapping,
         ActionForm form,
         HttpServletRequest request,
         HttpServletResponse response) throws Exception {
 
  LoginActionForm loginActinForm=(LoginActionForm)form;
  
  String username=null;
  String password=null;
  username = loginActinForm.getUsername().trim();
   password = loginActinForm.getPassword().trim();
   
   UserDAO userDAO=new UserDAO();
   
   boolean flag=false;
   flag=userDAO.isLogin(username, password);
   
   ActionMessages errors = new ActionMessages();
   if (!flag){
       errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.password.mismatch"));
   }

  if (!errors.isEmpty()) {
      saveErrors(request, errors);
      return (new ActionForward(mapping.getInput()));
     }
 
  HttpSession session = request.getSession();
  session.setAttribute("user", username);
 
  if (mapping.getAttribute() != null) {
             if ("request".equals(mapping.getScope()))
                 request.removeAttribute(mapping.getAttribute());
             else
                 session.removeAttribute(mapping.getAttribute());
         }
  
  return (mapping.findForward("success"));
 }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章