1 package org.springframework.samples.jpetstore.web.spring; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 6 import org.springframework.beans.support.PagedListHolder; 7 import org.springframework.samples.jpetstore.domain.Account; 8 import org.springframework.samples.jpetstore.domain.logic.PetStoreFacade; 9 import org.springframework.web.servlet.ModelAndView; 10 import org.springframework.web.servlet.mvc.Controller; 11 12 16 public class SignonController implements Controller { 17 18 private PetStoreFacade petStore; 19 20 public void setPetStore(PetStoreFacade petStore) { 21 this.petStore = petStore; 22 } 23 24 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { 25 String username = request.getParameter("username"); 26 String password = request.getParameter("password"); 27 Account account = this.petStore.getAccount(username, password); 28 if (account == null) { 29 return new ModelAndView("Error", "message", "Invalid username or password. Signon failed."); 30 } 31 else { 32 UserSession userSession = new UserSession(account); 33 PagedListHolder myList = new PagedListHolder(this.petStore.getProductListByCategory(account.getFavouriteCategoryId())); 34 myList.setPageSize(4); 35 userSession.setMyList(myList); 36 request.getSession().setAttribute("userSession", userSession); 37 String forwardAction = request.getParameter("forwardAction"); 38 if (forwardAction != null) { 39 response.sendRedirect(forwardAction); 40 return null; 41 } 42 else { 43 return new ModelAndView("index"); 44 } 45 } 46 } 47 48 } 49 | Popular Tags |