《WEB应用与开发》--网上购物系统--课程设计报告

2026/4/28 16:34:02

2、小类别显示,完成步骤同大类别显示

运行Tomcat,执行此部分操作,最终效果如图所示:

3、商品显示,完成步骤同大类别显示

运行Tomcat,执行此部分操作,最终效果如图所示:

4、添加商品到购物车

在商品的列表页面提供了添加到购物车的链接。单击Add to Cart链接可以把与之对应的商品添加入购物车中。要完成这个过程,需要执行一下步骤:

(1)设置链接,为商品添加链接,在商品上创建链接的代码如下: (2)设置配置文件,在web.xml中添加如下代码:

ItemServlet

org.bzc.jpetstore.servlets.ItemServlet

ItemServlet /item.do

(3)在src目录的org\\bzc\\jpetstore\\servlets文件夹中新建名为ProductServlet的类,Servlet本身并没有处理业务数据,而是调用ItemBiz类的相关方法操作,具体代码如下:

public class ProductServlet extends HttpServlet { public void init() throws ServletException { } public void destroy() { }

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException { doPost(request, response); }

public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

String path = request.getParameter(\ HttpSession session = request.getSession(); List listProduct = new ArrayList();

ProductBiz productbiz = new ProductBiz(); ItemBiz itembiz = new ItemBiz(); String tourl = \

if (\

String productId = request.getParameter(\ try {

List itemList = itembiz.searchByproductId(productId); Product product = (Product) productbiz.searchById(1, productId) .get(0);

session.setAttribute(\ session.setAttribute(\

}

} catch (Exception e) { e.printStackTrace();}

tourl = \ } else {

listProduct = productbiz.searchById(0, \ tourl = \

session.setAttribute(\}

request.getRequestDispatcher(tourl).forward(request, response); }

(4)编写Cart.jsp页面,来显示购物车中的商品项数据,Cart.jsp页面的部分代码如下:

action=\ntities\

href=\

artitem.item.itemid}\

${cartitem.item.itemid}

Item ID Product ID Description In Stock? Quantity List Price Total Cost  
${cartitem.item.productid}

${cartitem.item.attr1} ${cartitem.item.attr2} ${cartitem.item.attr3} ${cartitem.item.attr4} ${cartitem.item.attr5} ${product.name}

href=\art&workingItemId=${cartitem.item.itemid}\

src=\/>

Sub Total: ${cart.subTotal}

src=\\

 

运行Tomcat,执行此部分操作,最终效果如图所示:


《WEB应用与开发》--网上购物系统--课程设计报告.doc 将本文的Word文档下载到电脑

Copyright © 2021-2025 云题海 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:370150219 邮箱:370150219@qq.com
苏ICP备16052595号-3

× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219