1 package org.springframework.samples.jpetstore.web.struts; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 6 import org.apache.struts.action.ActionForm; 7 import org.apache.struts.action.ActionForward; 8 import org.apache.struts.action.ActionMapping; 9 10 import org.springframework.beans.support.PagedListHolder; 11 import org.springframework.samples.jpetstore.domain.Account; 12 13 public class SignonAction extends BaseAction { 14 15 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 16 request.getSession().removeAttribute("workingAccountForm"); 17 request.getSession().removeAttribute("accountForm"); 18 if (request.getParameter("signoff") != null) { 19 request.getSession().invalidate(); 20 return mapping.findForward("success"); 21 } 22 else { 23 AccountActionForm acctForm = (AccountActionForm) form; 24 String username = acctForm.getUsername(); 25 String password = acctForm.getPassword(); 26 Account account = getPetStore().getAccount(username, password); 27 if (account == null) { 28 request.setAttribute("message", "Invalid username or password. Signon failed."); 29 return mapping.findForward("failure"); 30 } 31 else { 32 String forwardAction = acctForm.getForwardAction(); 33 acctForm = new AccountActionForm(); 34 acctForm.setForwardAction(forwardAction); 35 acctForm.setAccount(account); 36 acctForm.getAccount().setPassword(null); 37 PagedListHolder myList = new PagedListHolder(getPetStore().getProductListByCategory(account.getFavouriteCategoryId())); 38 myList.setPageSize(4); 39 acctForm.setMyList(myList); 40 request.getSession().setAttribute("accountForm", acctForm); 41 if (acctForm.getForwardAction() == null || acctForm.getForwardAction().length() < 1) { 42 return mapping.findForward("success"); 43 } 44 else { 45 response.sendRedirect(acctForm.getForwardAction()); 46 return null; 47 } 48 } 49 } 50 } 51 52 } 53 | Popular Tags |