1 17 package servletunit.struts.tests; 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 DynamicAction extends Action { 26 27 public ActionForward execute(ActionMapping mapping, 28 ActionForm form, 29 HttpServletRequest request, 30 HttpServletResponse response) { 31 32 DynaActionForm dynaForm = (DynaActionForm) form; 33 String username = (String ) dynaForm.get("username"); 34 String password = (String ) dynaForm.get("password"); 35 36 ActionErrors errors = new ActionErrors(); 37 38 if ((!username.equals("deryl")) || (!password.equals("radar"))) 39 errors.add("password",new ActionMessage("error.password.mismatch")); 40 41 if (!errors.isEmpty()) { 42 saveErrors(request,errors); 43 return mapping.findForward("login"); 44 } 45 46 HttpSession session = request.getSession(); 47 session.setAttribute("authentication", username); 48 49 if (mapping.getAttribute() != null) { 51 if ("request".equals(mapping.getScope())) 52 request.removeAttribute(mapping.getAttribute()); 53 else 54 session.removeAttribute(mapping.getAttribute()); 55 } 56 57 return mapping.findForward("success"); 59 60 } 61 62 } 63 64 | Popular Tags |