• 大小: 2.26MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-12
  • 语言: Java
  • 标签: java  

资源简介

用java做的一个购物车,这购物车功能有对商品的增删改查和恢复商品信息

资源截图

代码片段和文件信息

package com.ycc.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ycc.bean.Cart;
import com.ycc.bean.CartItem;
import com.ycc.dao.ComputerDao;
import com.ycc.entity.Computer;
import com.ycc.util.CookieUtil;
import com.ycc.util.DaoFactory;

/**
 * Servlet implementation class ActionServlet
 */
public class ActionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ActionServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

protected void service(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
response.setContentType(“text/html;charset=utf-8“);
request.setCharacterEncoding(“utf-8“);
String uri=request.getRequestURI();
String str=uri.substring(uri.lastIndexOf(“/“)+1uri.lastIndexOf(“.do“));
ComputerDao dao=(ComputerDao)DaoFactory.getInstance(“ComputerDao“);
if(str.equalsIgnoreCase(“list“)){
List list=dao.findAll();
HttpSession session=request.getSession();
session.setAttribute(“computerList“list);
request.getRequestDispatcher(“computer_list.jsp“).forward(request response);
}else if(str.equalsIgnoreCase(“add“)){
int id=Integer.parseInt(request.getParameter(“id“));
Computer com=dao.findId(id);
HttpSession session=request.getSession();
CartItem cartItem=(CartItem)session.getAttribute(“CartItem“);
if(cartItem==null){
cartItem=new CartItem();
System.out.println(“CookieUtil.findCookie============“+CookieUtil.findCookie(“CartItem“ request));
cartItem.huifu(CookieUtil.findCookie(“CartItem“ request));
session.setAttribute(“CartItem“ cartItem);
}
Cart cart=new Cart();
cart.setComputer(com);
cart.setQty(1);


boolean bool=cartItem.addCart(cart);
if(bool==false){
System.out.println(“已经购买了“);
request.setAttribute(“buy_“+id“已经购买了“);
request.getRequestDispatcher(“list.do“).forward(request response);
}else{
System.out.println(“第一次购买“);
CookieUtil.addCookie(“CartItem“ cartItem.getSplit() response);
response.sendRedirect(“list.do“);
}
}else if(str.equalsIgnoreCase(“update“)){
int id=Integer.parseInt(request.getParameter(“id“));
int qty=Integer.parseInt(request.getParameter(“qty“));
HttpSession session=request.getSession();
CartItem ci=(CartItem)session.getAttribute(“CartItem“);
ci.updCart(id qty);
CookieUtil.addCookie(“CartItem“ ci.getSplit() response);
response.sendRedirect(“cart.jsp“);
}else if(str.equals(“del“)){
int id=Integer.parseInt(request.getParameter(“id“));
HttpSession session=request.getSession();
CartItem c

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        833  2013-02-05 09:54  shopping_test\.classpath

     文件       1046  2013-02-05 09:54  shopping_test\.project

     文件        503  2013-02-05 09:54  shopping_test\.settings\.jsdtscope

     文件        364  2013-02-05 09:54  shopping_test\.settings\org.eclipse.jdt.core.prefs

     文件        493  2013-02-05 09:54  shopping_test\.settings\org.eclipse.wst.common.component

     文件        345  2013-02-05 09:54  shopping_test\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2013-02-05 09:54  shopping_test\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2013-02-05 09:54  shopping_test\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件       4363  2013-02-15 10:48  shopping_test\build\classes\com\ycc\action\ActionServlet.class

     文件        742  2013-02-15 10:48  shopping_test\build\classes\com\ycc\bean\Cart.class

     文件       3591  2013-02-15 10:48  shopping_test\build\classes\com\ycc\bean\CartItem.class

     文件        270  2013-02-15 10:48  shopping_test\build\classes\com\ycc\dao\ComputerDao.class

     文件       2581  2013-02-15 10:48  shopping_test\build\classes\com\ycc\dao\ComputerDaoImpl.class

     文件       1340  2013-02-15 10:48  shopping_test\build\classes\com\ycc\entity\Computer.class

     文件       2759  2013-02-15 10:48  shopping_test\build\classes\com\ycc\util\ConnectionUtil.class

     文件       2638  2013-02-15 10:48  shopping_test\build\classes\com\ycc\util\CookieUtil.class

     文件       2201  2013-02-15 10:48  shopping_test\build\classes\com\ycc\util\DaoFactory.class

     文件         39  2013-02-05 10:32  shopping_test\build\classes\com\ycc\util\daoFactory.properties

     文件        140  2013-02-05 10:07  shopping_test\build\classes\com\ycc\util\mysql.properties

     文件       3213  2013-02-05 14:11  shopping_test\src\com\ycc\action\ActionServlet.java

     文件        368  2013-02-05 11:00  shopping_test\src\com\ycc\bean\Cart.java

     文件       2116  2013-02-08 16:38  shopping_test\src\com\ycc\bean\CartItem.java

     文件        189  2013-02-05 11:22  shopping_test\src\com\ycc\dao\ComputerDao.java

     文件       1689  2013-02-05 11:24  shopping_test\src\com\ycc\dao\ComputerDaoImpl.java

     文件        815  2013-02-05 10:24  shopping_test\src\com\ycc\entity\Computer.java

     文件       2030  2013-02-05 14:14  shopping_test\src\com\ycc\util\ConnectionUtil.java

     文件       1530  2013-02-05 14:22  shopping_test\src\com\ycc\util\CookieUtil.java

     文件       1039  2013-02-05 10:37  shopping_test\src\com\ycc\util\DaoFactory.java

     文件         39  2013-02-05 10:32  shopping_test\src\com\ycc\util\daoFactory.properties

     文件        140  2013-02-05 10:07  shopping_test\src\com\ycc\util\mysql.properties

............此处省略96个文件信息

评论

共有 条评论