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.samples.jpetstore.domain.Order; 11 12 public class ViewOrderAction extends SecureBaseAction { 13 14 protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 15 AccountActionForm acctForm = (AccountActionForm) form; 16 int orderId = Integer.parseInt(request.getParameter("orderId")); 17 Order order = getPetStore().getOrder(orderId); 18 if (acctForm.getAccount().getUsername().equals(order.getUsername())) { 19 request.setAttribute("order", order); 20 return mapping.findForward("success"); 21 } 22 else { 23 request.setAttribute("message", "You may only view your own orders."); 24 return mapping.findForward("failure"); 25 } 26 } 27 28 } 29 | Popular Tags |