• 大小: 58KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-26
  • 语言: Java
  • 标签: hibernate  jsp  

资源简介

基于jsp+hibernate网上购物系统,用mysql做数据库,tomcat做服务器

资源截图

代码片段和文件信息

package com.tarena.sd070935.action;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tarena.sd070935.biz.Cart;
import com.tarena.sd070935.entity.Item;
import com.tarena.sd070935.entity.Product;



public class AddItemToCartAction extends Action
{
public Product getProductById(List productsint id){
Iterator it=products.iterator();
while(it.hasNext()){
Product pr=(Product)it.next();
if(pr.getId()==id){
return pr;
}
}
return null;
}
public int isProduct(Cart cartProduct product){
     HashMap list=cart.getCartItem();
     Iterator it=list.keySet().iterator();
     int number=0;
while(it.hasNext()){
Integer key=(Integer)it.next();
Item item=(Item)list.get(key);
number=item.getNumber();
if(item.getProduct()==product){
item.setNumber(number+1);
return number+1;
}
}
return 1;
}
  public ActionForward execute(ActionMapping mapping 
                                  ActionForm form 
                                    HttpServletRequest request 
                                      HttpServletResponse response)throws Exception
  {
    if(request.getSession().getAttribute(“user“)==null){
    return mapping.findForward(“login“);
    }
    
    if(request.getSession().getAttribute(“cart“)==null){
     return mapping.findForward(“login“);
    }
    
    Cart cart=(Cart)request.getSession().getAttribute(“cart“);
    List products=(List)request.getSession().getAttribute(“productlist“);
   
    int id=Integer.parseInt(request.getParameter(“id“));
    try{
     if(cart.getCartItem()==null){
     cart.addItem(getProductById(productsid)1);
     }else
     cart.addItem(getProductById(productsid)this.isProduct(cartgetProductById(productsid)));
     request.getSession().setAttribute(“cart“ cart);
        return mapping.findForward(“addtocart“);
    }catch(Exception e){
     e.printStackTrace();
     return mapping.findForward(“error“);
    }
  }

}

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

     文件       1416  2008-02-20 13:07  shoppingcart\.project

     文件       1601  2008-02-23 02:26  shoppingcart\src\com\tarena\sd070935\entity\User.java

     文件        617  2008-02-20 14:37  shoppingcart\src\com\tarena\sd070935\entity\Product.java

     文件        755  2008-02-25 11:42  shoppingcart\src\com\tarena\sd070935\entity\Item.java

     文件        896  2008-02-25 11:50  shoppingcart\src\com\tarena\sd070935\entity\Order.java

     文件        773  2008-02-20 19:59  shoppingcart\src\com\tarena\sd070935\entity\Order.hbm.xml

     文件        905  2008-02-21 10:47  shoppingcart\src\com\tarena\sd070935\entity\User.hbm.xml

     文件        694  2008-02-25 02:52  shoppingcart\src\com\tarena\sd070935\entity\Item.hbm.xml

     文件        599  2008-02-20 21:04  shoppingcart\src\com\tarena\sd070935\entity\Product.hbm.xml

     目录          0  2008-02-20 13:35  shoppingcart\src\com\tarena\sd070935\entity

     文件        452  2008-02-23 02:08  shoppingcart\src\com\tarena\sd070935\persistent\ShoppingCartDAO.java

     文件       2190  2008-02-23 02:09  shoppingcart\src\com\tarena\sd070935\persistent\ShoppingCartDAOImpl.java

     文件        371  2008-02-21 14:09  shoppingcart\src\com\tarena\sd070935\persistent\TestHbn.java

     文件        623  2008-02-21 15:40  shoppingcart\src\com\tarena\sd070935\persistent\TestService.java

     文件       2331  2008-02-25 03:15  shoppingcart\src\com\tarena\sd070935\persistent\Test.java

     文件        275  2008-02-21 13:57  shoppingcart\src\com\tarena\sd070935\persistent\ShoppingCartDAOFactory.java

     目录          0  2008-02-20 16:10  shoppingcart\src\com\tarena\sd070935\persistent

     文件        688  2008-02-20 21:13  shoppingcart\src\com\tarena\sd070935\util\HbnUtil.java

     目录          0  2008-02-20 21:09  shoppingcart\src\com\tarena\sd070935\util

     文件       2184  2008-02-27 00:06  shoppingcart\src\com\tarena\sd070935\biz\Cart.java

     文件        451  2008-02-23 02:16  shoppingcart\src\com\tarena\sd070935\biz\LoginBiz.java

     文件        428  2008-02-25 03:29  shoppingcart\src\com\tarena\sd070935\biz\ProductList.java

     文件        433  2008-02-23 02:09  shoppingcart\src\com\tarena\sd070935\biz\RegistUser.java

     文件        441  2008-02-25 03:33  shoppingcart\src\com\tarena\sd070935\biz\SaveOrder.java

     目录          0  2008-02-22 09:40  shoppingcart\src\com\tarena\sd070935\biz

     文件       1460  2008-02-28 22:44  shoppingcart\src\com\tarena\sd070935\action\LoginAction.java

     文件       1059  2008-02-22 12:10  shoppingcart\src\com\tarena\sd070935\action\LoginForm.java

     文件       1665  2008-02-23 19:34  shoppingcart\src\com\tarena\sd070935\action\ProductAction.java

     文件       1810  2008-02-28 22:37  shoppingcart\src\com\tarena\sd070935\action\RegistAction.java

     文件       2491  2008-02-24 21:45  shoppingcart\src\com\tarena\sd070935\action\AddItemToCartAction.java

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

评论

共有 条评论