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 NewOrderAction extends SecureBaseAction { 13 14 protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 15 OrderActionForm orderForm = (OrderActionForm) form; 16 if (orderForm.isShippingAddressRequired()) { 17 return mapping.findForward("shipping"); 18 } 19 else if (!orderForm.isConfirmed()) { 20 return mapping.findForward("confirm"); 21 } 22 else if (orderForm.getOrder() != null) { 23 Order order = orderForm.getOrder(); 24 getPetStore().insertOrder(order); 25 request.getSession().removeAttribute("workingOrderForm"); 26 request.getSession().removeAttribute("cartForm"); 27 request.setAttribute("order", order); 28 request.setAttribute("message", "Thank you, your order has been submitted."); 29 return mapping.findForward("success"); 30 } 31 else { 32 request.setAttribute("message", "An error occurred processing your order (order was null)."); 33 return mapping.findForward("failure"); 34 } 35 } 36 37 } 38 | Popular Tags |