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

资源简介

基于JSP+mysql基于JSP+mysql

资源截图

代码片段和文件信息

package mrgf.action;

import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import mrgf.hibernate.*;
import mrgf.other.*;
import mrgf.form.ContentForm;

public class ContentAction extends Action {
    public ActionForward execute(ActionMapping mapping ActionForm form
                                 HttpServletRequest request
                                 HttpServletResponse response) {
        ContentForm contentForm = (ContentForm) form;
        String p = mapping.getParameter();
        String forward = ““;
        //添加至购物车
        if (p.equals(“addToCart“)) {
            int id = Integer.parseInt(request.getParameter(“merchandiseId“));
            String hql = “from MerchandiseInfo where id=“ + id;
            Hibernate hn = new Hibernate();
            MerchandiseInfo merchandiseInfo = (MerchandiseInfo) hn.queryOne(hql); //初始化代表该商品的对象
            HttpSession session = request.getSession();
            List shoppingCart = (List) session.getAttribute(“shoppingCart“); // 从Session中获取模拟购物车的List型属性
            if (shoppingCart == null) { // 如果为空则表示用户还没购买任何商品
                shoppingCart = new ArrayList(); //则新声名一个List属性
                shoppingCart.add(merchandiseInfo); //并直接将代表购买商品的对象放入该新声名的属性
            } else { // 否则表示用户已经购买了商品
                id = merchandiseInfo.getId();
                // 判断购物车中是否已经包含该商品,如果包含则在原购买数量上加1
                boolean add = false;
                for (int i = 0; i < shoppingCart.size(); i++) {
                    MerchandiseInfo info = (MerchandiseInfo) shoppingCart.get(i);
                    if (info.getId() == id) {
                        info.setAmount(info.getAmount() + 1);
                        shoppingCart.add(i info);
                        shoppingCart.remove(i);
                        add = true; //如果包含,则将add该改为true
                        break;
                    }
                }
                // 如果add为false,则表示在购物车中不包含该商品,将该商品添加到购物车中
                if (add == false) {
                    shoppingCart.add(merchandiseInfo);
                }
            }
            request.setAttribute(“previousPage“
                                 request.getParameter(“previousPage“));
            session.setAttribute(“shoppingCart“ shoppingCart); //再保存在Session中
            forward = “shopping_cart“;
        }

        //清空购物车
        if (p.equals(“clearCart“)) {
            HttpSession session = request.getSession();
            session.removeAttribute(“shoppingCart“);
            forward = “shopping_cart“;
        }

        //清空购物车中的某一商品
        if (p.equals(“moveFromCart“)) {
            int id = Integer.parseInt(request.getParameter(“merchandiseId“));
//            String merchandiseId = request.getParameter(“merchandiseId“);
//            int id = Integer.parseInt(merchandiseId);
            HttpSession session = request.getSession();
            List shoppingCart = (List) session.getAttribute(“sho

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

     文件      11282  2007-09-06 09:49  ShoppingMallProject\.classpath

     文件        440  2007-03-10 14:01  ShoppingMallProject\.myhibernatedata

     文件        342  2007-09-07 11:25  ShoppingMallProject\.mymetadata

     文件        244  2007-03-10 14:00  ShoppingMallProject\.mystrutsdata

     文件       1522  2007-09-05 16:34  ShoppingMallProject\.project

     文件       6104  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_check-out.jsp

     文件       1437  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_clue_on.jsp

     文件       4347  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_index.jsp

     文件      14005  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_layout.jsp

     文件       6402  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_login.jsp

     文件       2459  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_merchandise_info.jsp

     文件       4759  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_merchandise_search.jsp

     文件       7200  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_new_merchandise.jsp

     文件       4223  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_see_order_for_goods.jsp

     文件       5274  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_see_order_info.jsp

     文件       5736  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_shopping_cart.jsp

     文件       7366  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_special_offer.jsp

     文件      13488  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_taxis.jsp

     文件       6360  2007-03-23 10:28  ShoppingMallProject\defaultroot\a_update_data.jsp

     文件       4365  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_ad.jsp

     文件       2351  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_index.jsp

     文件       2155  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_layout.jsp

     文件       7550  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_manager.jsp

     文件       5300  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_member.jsp

     文件       5932  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_merchandise.jsp

     文件       5849  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_merchandise_add.jsp

     文件       6121  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_merchandise_info.jsp

     文件       6611  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_order.jsp

     文件       8297  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_order_particular.jsp

     文件       3635  2007-03-23 10:28  ShoppingMallProject\defaultroot\b_sort_add.jsp

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

评论

共有 条评论

相关资源