public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // create action errors incase login fails ActionMessages errors = new ActionMessages(); saveErrors(request,errors); DynaValidatorForm theForm = (DynaValidatorForm) form; CustomerDAO customerDAO = ServiceFactory.instance().createCustomerDAO(); String customerIDEntered = (String) theForm.get("customerID"); Customer customer = customerDAO.loadCustomer(customerIDEntered); if(customer == null) { customerDAO = ServiceFactory.instance().createPotentialCustomerDAO(); customer = customerDAO.loadCustomer(customerIDEntered); if(customer != null) { // customer is awaiting activation errors.add("userAwaitingVerification", new ActionMessage("login.userAwaitingVerification")); } else { // unknown customer errors.add("userUnknown", new ActionMessage("login.userUnknown")); } // customer wasn't found in verified or potential customer storage return mapping.findForward("error"); } else { /* found customer now create session adding the customer object to save retrieving the * customer details during the session **/ HttpSession session = request.getSession(); session.setAttribute("customer", customer); // create cookie to remember customers name for next visit Cookie customerNameCookie = new Cookie("customerName", customer.getFirstName()+customer.getLastName()); response.addCookie(customerNameCookie); return mapping.findForward("success"); } }