1 17 package examples; 18 19 import org.apache.struts.action.*; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import javax.servlet.http.HttpSession ; 24 25 public class LoginAction extends Action { 26 27 public ActionForward execute(ActionMapping mapping, 28 ActionForm form, 29 HttpServletRequest request, 30 HttpServletResponse response) { 31 32 String username = ((LoginForm) form).getUsername(); 33 String password = ((LoginForm) form).getPassword(); 34 35 ActionErrors errors = new ActionErrors(); 36 37 if ((!username.equals("deryl")) || (!password.equals("radar"))) 38 errors.add("password",new ActionError("error.password.mismatch")); 39 40 if (!errors.isEmpty()) { 41 saveErrors(request,errors); 42 return new ActionForward(mapping.getInput()); 43 } 44 45 HttpSession session = request.getSession(); 46 session.setAttribute("authentication", username); 47 48 50 return mapping.findForward("success"); 51 52 } 53 54 } 55 56 57 58 59 60 61 62 | Popular Tags |