• 大小: 10.66MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-09
  • 语言: Java
  • 标签: Servlet  购物车  

资源简介

jsp+servlet +hibernate 购物车系统

资源截图

代码片段和文件信息

package com.tarena.wangkai.shoppingCart.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Iterator;

import javax.servlet.RequestDispatcher;
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.tarena.wangkai.shoppingCart.entity.Cart;
import com.tarena.wangkai.shoppingCart.entity.Product;
/**
 * ervlet
 * @author wangkai
 *
 */
public class AccessMyShoppingCartServlet extends HttpServlet {

private static final long serialVersionUID = 358755617261259534L;
private static Collection products;

@Override
protected void doGet(HttpServletRequest req HttpServletResponse resp)
throws ServletException IOException {
products=(Collection)getServletContext().getAttribute(“products“);

req.setCharacterEncoding(“gbk“);
resp.setCharacterEncoding(“gbk“);

HttpSession session=req.getSession();
Cart myCart=(Cart)session.getAttribute(“myCart“);
PrintWriter out=resp.getWriter();

String action=req.getParameter(“does“).trim();
if(action != null && action.length()>0){
if(action.equals(“add“)){
String productIdStr=req.getParameter(“productId“);
if(productIdStr!=null && productIdStr.length()>0){
int productId=Integer.parseInt(productIdStr);
if(products!=null){
Iterator it=products.iterator();
while(it.hasNext()){
  Product p=(Product)it.next();
  if(p.getId() == productId){
if(myCart == null){
myCart=new Cart();
switch(myCart.addItem(p 1)){
case -1:out.println(“ript>alert(‘add fail‘);history.back();ript>“);
break;
case 0:out.println(“ript>alert(‘can not add the same product again‘);history.back();ript>“);
break;
case 1:out.println(“ript>alert(‘add seccess‘);history.back();ript>“);
break;
}
session.setAttribute(“myCart“ myCart);
}else{
switch(myCart.addItem(p 1)){
case -1:out.println(“ript>alert(‘add fail‘);history.back();ript>“);
break;
case 0:out.println(“ript>alert(‘can not add the same product again‘);history.back();ript>“);
break;
case 1:out.println(“ript>alert(‘add seccess‘);history.back();ript>“);
break;
}
}
}
}
}
}
}else if(action.equals(“modify“)){
String changeStr=req.getParameter(“changes“).trim();
if(changeStr!=null && changeStr.length()>0){
String[] allChanges=changeStr.split(“#“);
for(int i=0;i String[] eachChange=allChanges[i].split(“:“);
int productId=Integer.parseInt(eachChange[0]);
int number=Integer.parseInt(eachChange[1]);
myCa

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

     文件        439  2009-05-11 09:55  shoppingCart\.classpath

     文件        417  2009-05-11 09:55  shoppingCart\.myhibernatedata

     文件        309  2009-05-18 15:26  shoppingCart\.mymetadata

     文件       1382  2009-05-11 10:00  shoppingCart\.project

     文件       4312  2009-05-31 16:50  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\AccessMyShoppingCartServlet.java

     文件       7561  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\ActionServlet.java

     文件       4033  2009-05-11 13:28  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\AjaxHandlerServlet.java

     文件        900  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\CharacterEncodingFilter.java

     文件       1570  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\CheckUserFilter.java

     文件        908  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\LogoutServlet.java

     文件       4074  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\ManagerActionServlet.java

     文件       1450  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\token\ImageTokenServlet.java

     文件       2821  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\action\token\TokenUtil.java

     文件        202  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\AdminDao.java

     文件        427  2009-05-12 08:38  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\impl\AdminDaoImpl.java

     文件       3033  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\impl\ManagerDaoImpl.java

     文件        882  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\impl\OrderDaoImpl.java

     文件        856  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\impl\ProductDaoImpl.java

     文件       4612  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\impl\ShoppingCartDAOImpl.java

     文件        676  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\impl\UserDaoImpl.java

     文件        518  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\ManagerDao.java

     文件        822  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\OrderDao.java

     文件         86  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\OrderItemDao.java

     文件        478  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\ProductDao.java

     文件        900  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\ShoppingCartDAO.java

     文件        420  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\dao\UserDao.java

     文件        593  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\entity\Admin.hbm.xml

     文件        459  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\entity\Admin.java

     文件       3237  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\entity\Cart.java

     文件        775  2009-05-11 09:54  shoppingCart\src\com\tarena\wangkai\shoppingCart\entity\Item.hbm.xml

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

评论

共有 条评论