购物车模块总结3
来源:互联网 发布:八门神器软件下载 编辑:程序博客网 时间:2024/04/29 18:27
BuyCartManageAction类的详细代码:用于处理购物车的修改,删除,清空等功能
中间return mapping.findForward("directUrl");这条语句用来跳转至全局配置的页面
<global-forwards>
<forward name="message" path="/WEB-INF/page/share/message.jsp" />
<forward name="directUrl" path="/WEB-INF/page/share/directUrl.jsp"/>
</global-forwards>
跳转至directUrl.jsp,
该页面使用了<c:redirect url="${directUrl}"/>,再跳转至directUrl对应的页面
@Controller("/shopping/cart/manage")
public class BuyCartManageAction extends DispatchAction {
/**
* 清空购物车
*/
public ActionForward deleteAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
BuyCart cart = WebUtil.getBuyCart(request);
cart.deleteAll();
BuyCartForm formbean = (BuyCartForm)form;
String param = formbean.getDirectUrl()!=null && !"".equals(formbean.getDirectUrl()) ? "?directUrl=" + formbean.getDirectUrl() : "";
request.setAttribute("directUrl", "/shopping/cart.do"+ param);
return mapping.findForward("directUrl");
}
/**
* 删除购物项
*/
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
BuyCartForm formbean = (BuyCartForm)form;
BuyCart cart = WebUtil.getBuyCart(request);
ProductInfo product = new ProductInfo(formbean.getProductid());
product.addProductStyle(new ProductStyle(formbean.getStyleid()));
BuyItem item = new BuyItem(product);
cart.deleteBuyItem(item);
String param = formbean.getDirectUrl()!=null && !"".equals(formbean.getDirectUrl()) ? "?directUrl=" + formbean.getDirectUrl() : "";
request.setAttribute("directUrl", "/shopping/cart.do"+ param);
return mapping.findForward("directUrl");
}
/**
* 修改购买数量
*/
public ActionForward updateAmount(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
setAmount(request);
BuyCartForm formbean = (BuyCartForm)form;
String param = formbean.getDirectUrl()!=null && !"".equals(formbean.getDirectUrl()) ? "?directUrl=" + formbean.getDirectUrl() : "";
request.setAttribute("directUrl", "/shopping/cart.do"+ param);
return mapping.findForward("directUrl");
}
/**
* 修改商品购买数量
* @param request
*/
private void setAmount(HttpServletRequest request) {
BuyCart cart = WebUtil.getBuyCart(request);
for(BuyItem item : cart.getItems()){
String paramName = "amount_"+ item.getProduct().getId()+"_"+
item.getProduct().getStyles().iterator().next().getId();
Integer amount = new Integer(request.getParameter(paramName));
item.setAmount(amount);
}
}
/**
* 结算
*/
public ActionForward settleAccounts(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
setAmount(request);
BuyCartForm formbean = (BuyCartForm)form;
String url = "/customer/shopping/deliver.do";
if(formbean.getDirectUrl()!=null && !"".equals(formbean.getDirectUrl())){
url = new String(Base64.decodeBase64(formbean.getDirectUrl().trim().getBytes()));//获取解码后的url
}
request.setAttribute("directUrl", url);
return mapping.findForward("directUrl");
}
}
- 购物车模块总结3
- 购物车模块总结1
- 购物车模块总结2
- 购物车模块设计
- 购物车模块myshoppingcart
- 购物车模块
- 购物车模块测试
- ECshop--购物车模块
- 图书商城:购物车模块
- 购物车模块的功能设计
- 购物车模块系统的开发
- PHP小白之路3--PHP之购物车模块设计
- 用JSP实现的商城购物车模块
- phpcms v9 商品购物车模块 不影响升级 二次开发
- 商品添加到购物车模块java程序
- 深入PHP购物车模块功能分析(函数讲解,附源码)
- 开发购物车模块中遇到的问题
- 商城购物车模块-自定义数字加减控件
- Extjs4.1.1API解读之误导篇(Ext.windows.MessageBox⇒buttonText)
- 时间的正则表达式,包括闰年和闰月的表达式
- javascript的parseFloat()方法精度问题
- JSF和Spring的集成
- java中timer类的使用
- 购物车模块总结3
- 蝴蝶兰与鳞托菊
- public static Bitmap createScaledBitmap(Bitmap unscaledBitmap, int dstWidth, int dstHeight,
- Jmeter分布式压测布署
- OPhone平台2D游戏引擎实现——场景、图层、元素(一)
- 用户访谈中的十大技巧
- Myeclipse启动的默认空间设置
- 黑马程序员之ADO.NET学习笔记: SqlTransaction(事务)
- Digester解释xml 两种rule方式