package com.clrl.webshop.web.actions;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.upload.FormFile;
import com.clrl.webshop.biz.GoodsHandler;
import com.clrl.webshop.commons.CartItem;
import com.clrl.webshop.commons.PageCW;
import com.clrl.webshop.commons.PageRpcBean;
import com.clrl.webshop.persist.BigType;
import com.clrl.webshop.persist.Goods;
import com.clrl.webshop.persist.SmallType;
import com.clrl.webshop.web.forms.GoodsForm;
/**
* 商品表action
* @author ChengWei
*
*/
public class GoodsAction extends DispatchAction {
private GoodsHandler goodsHandler;
// 查询特价商品(ChengWei)
public ActionForward findTeJiaGoods(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PageCW pageCW = new PageCW();
int pageSize = 4; // 每页显示 行 数
int page = 1; // 当前 页
int pageCount = 1; // 总页 数
int totalRow = 0; // 总记录
try {
page = Integer.parseInt(request.getParameter("page"));
} catch (Exception e) {
page = 1;
}
List teJiaGoodsList = goodsHandler.findListForPage("from Goods g where g.mark=1", (page - 1) * pageSize, pageSize);
totalRow = goodsHandler.findTotalRow("select count(*) from Goods g where g.mark=1 and g.number>0");
if (totalRow % pageSize == 0) {
pageCount = totalRow / pageSize;
} else {
pageCount = totalRow / pageSize + 1;
}
pageCW.setPage(page);
pageCW.setPageCount(pageCount);
pageCW.setTotalRow(totalRow);
pageCW.setList(teJiaGoodsList);
request.setAttribute("pageCW", pageCW);
return mapping.findForward("default");
}
// 查询新品(ChengWei)
public ActionForward findNewGoods(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List newGoodsList = goodsHandler.findListForPage("from Goods g where g.number>0 order by g.creaTime desc", 0, 10);
request.setAttribute("newGoodsList", newGoodsList);
return mapping.findForward("default");
}
// 销售排行(ChengWei)
public ActionForward findGoodsSort(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List goodsSortList = goodsHandler.findListForPage("from Goods g where g.number>0 order by g.number desc", 0, 10);
request.setAttribute("goodsSortList", goodsSortList);
request.setAttribute("type", "findGoodsSort");
return mapping.findForward("default");
}
// 通过小商品类型查询商品(ChengWei)
public ActionForward findGoodsBySmallId(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String smallId = request.getParameter("smallId");
if (smallId != null) {
PageCW pageCW = new PageCW();
int pageSize = 4; // 每页显示 行 数
int page = 1; // 当前 页
int pageCount = 1; // 总页 数
int totalRow = 0; // 总记录
try {
page = Integer.parseInt(request.getParameter("page"));
} catch (Exception e) {
page = 1;
}
List smallGoodsList = goodsHandler.findListForPage("from Goods g where g.number>0 and g.smallType.id="+Integer.parseInt(smallId), (page - 1) * pageSize, pageSize);
totalRow = goodsHandler.findTotalRow("select count(*) from Goods g where g.number>0 and g.smallType.id="+Integer.parseInt(smallId));
if (totalRow % pageSize == 0) {
pageCount = totalRow / pageSize;
} else {
pageCount = totalRow / pageSize + 1;
}
pageCW.setPage(page);
pageCW.setPageCount(pageCount);
pageCW.setTotalRow(totalRow);
pageCW.setList(smallGoodsList);
request.setAttribute("smallId", smallId);
request.setAttribute("pageCW", pageCW);
request.setAttribute("type", "fg-selectNewGoods");
}
return mapping.findForward("default");
}
// 查询商品详细信息 (ChengWei)
public ActionForward findGoodsById(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String id = request.getParameter("id");
if (id != null) {
Goods goods = goodsHandler.findGoodsById(Integer.parseInt(id));
request.setAttribute("goods", goods);
}
return mapping.findForward("findGoodsById");
}
//*******************购物车(map实现)************************//
public ActionForward cart(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
String path = request.getParameter("path");
Map cart = (Map)session.getAttribute("cart"); // 从session拿到购物车
String id = request.getParameter("id"); // 得到商品id
double totalPrice = 0;// 商品总价
CartItem cartItem = null; // 购物车里的商品
Goods goods = null; // 商品
if (path.equals("add")) { // 添加商品到 购物车
if (cart == null) {
cart = new HashMap();
cartItem = new CartItem();
goods = goodsHandler.findGoodsById(Integer.parseInt(id));
cartItem.setGoods(goods);
cartItem.setCount(1);
cart.put(id, cartItem);
} else {
cartItem = (CartItem)cart.get(id);
if (cartItem == null) {
cartItem = new CartItem();
goods = goodsHandler.findGoodsById(Integer.parseInt(id));
cartItem.setGoods(goods);
cartItem.setCount(1);
cart.put(id, cartItem);
} else {
if (!(cartItem.getCount() >= cartItem.getGoods().getNumber())) { // 判断购物车里的数量是否大于 数据库里的商品数量
cartItem.setCount(cartItem.getCount()+1);
}
}
}
//算出总价
if (cart != null && cart.size() > 0) {
for (Object obj : cart.values()) {
CartItem item = (CartItem)obj;
if (item.getGoods().getFreePrice() != 0) {
totalPrice += item.getCount() * item.getGoods().getFreePrice();
} else {
totalPrice += item.getCount() * item.getGoods().getNowPrice();
}
}
}
session.setAttribute("totalPrice", totalPrice);
session.setAttribute("cart", cart);
request.setAttribute("addCartSuccess", "addCartSuccess");
return mapping.findForward("findGoodsById");
} else if (path.equals("del")) { // 删除商品
cart.remove(id);
} else if (path.equals("modify")) { // 修改数量
String count = request.getParameter("count");
cartItem = (CartItem)cart.get(id);
cartItem.setCount(Integer.parseInt(count));
} else if (path.equals("clear")) { // 清空购物车
cart.clear();
}
//算出总价
if (cart != null && cart.size() > 0) {
for (Object obj : cart.values()) {
CartItem item = (CartItem)obj;
if (item.getGoods().getFreePrice() != 0) {
totalPrice += item.getCount() * item.getGoods().getFreePrice();
} else {
totalPrice += item.getCount() * item.getGoods().getNowPrice();
}
}
}
request.setAttribute("cart", cart);
session.setAttribute("totalPrice", totalPrice);
request.setAttribute("type", "cart");
return mapping.findForward("default");
}
public void setGoodsHandler(GoodsHandler goodsHandler) {
this.goodsHandler = goodsHandler;
}
/*
* 分页查询商品,大类型,小类型,特价商品(RPC)(non-Javadoc)
* @see org.apache.struts.actions.DispatchAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ActionForward doQuery(ActionMapping mapping, ActionForm form,
没有合适的资源?快使用搜索试试~ 我知道了~
企业电子商务网前台+后台(SSH+mysql5.0)
共562个文件
svn-base:232个
class:76个
java:68个
3星 · 超过75%的资源 需积分: 9 92 下载量 167 浏览量
2009-12-21
22:00:53
上传
评论 5
收藏 1.85MB RAR 举报
温馨提示
本系统采用SSH核心技术,由于上传文件大小限制的原因!本包中没有保留SSH集成的包!自己导入SSH的包就可以运行此项目!!含有40多张页面!基本SSH的功能都运用进去了!前台+后台管理电子商务!可以实现购物车,订单等功能
资源推荐
资源详情
资源评论
收起资源包目录
企业电子商务网前台+后台(SSH+mysql5.0) (562个子文件)
GoodsAction.class 11KB
MemberDAO.class 8KB
OrderDAO.class 8KB
GoodsDAO.class 8KB
ManagerDAO.class 8KB
OrderHandlerImpl.class 7KB
AfficheDAO.class 6KB
OrderDetailDAO.class 6KB
SmallTypeDAO.class 6KB
LinkDAO.class 6KB
BigTypeDAO.class 6KB
AfficheAction.class 6KB
MemberAction.class 5KB
ManagerAction.class 5KB
OrderAction.class 4KB
SmallTypeAction.class 4KB
Goods.class 4KB
GoodsHandlerImpl.class 4KB
AfficheHandlerImpl.class 3KB
BigTypeAction.class 3KB
MemberHandlerImpl.class 3KB
SmallTypeHandlerImpl.class 3KB
Order.class 3KB
Member.class 3KB
LinkAction.class 3KB
ManagerHandlerImpl.class 3KB
HibernateSessionFactory.class 2KB
ManagerPage.class 2KB
PageRpcBean.class 2KB
AffichePage.class 2KB
MemberPage.class 2KB
PageOrder.class 2KB
BigTypeHandlerImpl.class 2KB
SmallType.class 2KB
LinkHandlerImpl.class 2KB
OrderDetail.class 2KB
GoodsDAO$1.class 2KB
Manager.class 2KB
Affiche.class 2KB
BigType.class 2KB
InvalidateAction.class 1KB
ManagerFilter.class 1KB
GoodsDAO$2.class 1KB
UtilDateConverter.class 1KB
ManagerDAO$1.class 1KB
MemberDAO$1.class 1KB
OrderDAO$1.class 1KB
SmallTypeDAO$1.class 1KB
BigTypeDAO$1.class 1KB
LinkDAO$1.class 1KB
Link.class 1KB
PageCW.class 1KB
GoodsForm.class 984B
RequestEncoding.class 929B
UtilDateConverterInitWithServlet.class 928B
CartItem.class 884B
OrderDetailHandlerImpl.class 837B
GoodsHandler.class 778B
OrderHandler.class 748B
OrderDetailForm.class 740B
AfficheHandler.class 722B
SmallTypeForm.class 720B
AfficheForm.class 700B
BigTypeForm.class 700B
ManagerForm.class 700B
MemberForm.class 690B
OrderForm.class 680B
CountTime.class 674B
LinkForm.class 670B
MemberHandler.class 655B
ManagerHandler.class 636B
MySqlserverDialect.class 632B
SmallTypeHandler.class 529B
BigTypeHandler.class 380B
LinkHandler.class 359B
OrderDetailHandler.class 216B
.classpath 9KB
css.css 4KB
entries 5KB
entries 4KB
entries 3KB
entries 2KB
entries 2KB
entries 2KB
entries 2KB
entries 1KB
entries 1KB
entries 955B
entries 897B
entries 790B
entries 786B
entries 615B
entries 615B
entries 602B
entries 600B
entries 493B
entries 487B
entries 482B
entries 481B
entries 477B
共 562 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
- yellow_fish12014-02-23不能使用,但是还是可以借鉴的
- 木炎20192018-09-10谢谢分享,很好的资源!谢谢CSDN
- 啪滋啪滋书生2013-07-26是啊,骗人的
- lyyss552255222012-03-02最讨厌标题与实际不符,虽然是电子商务的系统,可是并不是用的mysql数据库。
- ka_ma2013-01-23最讨厌标题与实际不符,虽然是电子商务的系统,可是并不是用的mysql数据库。
RPC409915396
- 粉丝: 3
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Pytorch-pytorch深度学习教程之深度残差网络.zip
- Pytorch-pytorch深度学习教程之循环神经网络.zip
- Pytorch-pytorch深度学习教程之逻辑回归.zip
- Pytorch-pytorch深度学习教程之双向循环网络.zip
- Pytorch-pytorch深度学习教程之卷积神经网络.zip
- Pytorch-pytorch深度学习教程之前馈神经网络.zip
- Pytorch-pytorch深度学习教程之线性回归.zip
- Pytorch-pytorch深度学习教程之基本操作.zip
- 基于QT的地图可视化桌面系统后台数据库为MySQL5.7源码.zip
- 基于simulink的PLL锁相环系统仿真【包括模型,文档,参考文献,操作步骤】
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功