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.samples.jpetstore.domain.Cart; 7 import org.springframework.web.servlet.ModelAndView; 8 import org.springframework.web.servlet.mvc.Controller; 9 import org.springframework.web.util.WebUtils; 10 11 15 public class ViewCartController implements Controller { 16 17 private String successView; 18 19 public void setSuccessView(String successView) { 20 this.successView = successView; 21 } 22 23 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { 24 UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request, "userSession"); 25 Cart cart = (Cart) WebUtils.getOrCreateSessionAttribute(request.getSession(), "sessionCart", Cart.class); 26 String page = request.getParameter("page"); 27 if (userSession != null) { 28 if ("next".equals(page)) { 29 userSession.getMyList().nextPage(); 30 } 31 else if ("previous".equals(page)) { 32 userSession.getMyList().previousPage(); 33 } 34 } 35 if ("nextCart".equals(page)) { 36 cart.getCartItemList().nextPage(); 37 } 38 else if ("previousCart".equals(page)) { 39 cart.getCartItemList().previousPage(); 40 } 41 return new ModelAndView(this.successView, "cart", cart); 42 } 43 44 } 45 | Popular Tags |