版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 WEB应用与开发课程设计报 告设计题目: 网上购物系统一、设计时间 2016年5月 04日-6月08日总的设计时间为1周, 第17周。具体安排如下:1、分析设计准备阶段(第17周周一至周二) 2、编程调试阶段(第17周周三至第17周周四) 3、书写设计报告和书写说明书阶段(第17周周五) 4、考核阶段(第17周周五) 二、设计地点 信息科学与工程学院机房三、算法及流程图(一)功能模块的实现系统功能模块的划分前台系统顺序流程图1、大类别显示应用程序的首页只提供了一个Enter the Store的链接时,将导航到大类别页面,要完成这个过程,需要执行一下步骤: (1)设置链接,为“Enter t
2、he Store”添加链接,代码如下: Enter the Store (2)设置配置文件,在web.xml中添加如下代码: IndexServletorg.bzc.jpetstore.servlets.IndexServlet IndexServlet/index.do (3)在src目录的orgbzcjpetstoreservlets文件夹中新建名为IndexServlet的类,Servlet本身并没有处理业务数据,而是调用CategoryBiz类的相关方法操作,具体代码如下: public class IndexServlet extends HttpServlet public voi
3、d doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doPost(request, response);public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException CategoryBiz categorybiz = new CategoryBiz();String tourl =
4、 ; /因为其他页面也需要获取大类别数据,所以存放于session中 HttpSession session = request.getSession(); /初始化一个List对象,用来存储大类别数据List list = new ArrayList();try /调用业务对象获取数据list = categorybiz.searchById(0, );tourl = /catalog/Main.jsp; catch (Exception e) tourl = index.html;e.printStackTrace();session.setAttribute(categroyList,
5、list);request.getRequestDispatcher(tourl).forward(request, response); (4)在src目录的orgbzcjpetstorebiz文件夹中新建名为CategoryBiz的类,CategoryBiz与数据库进行相互。此处需要查询的是所有的大类别数据,后面还需要根据大类别ID查询大类别数据,将这两部分整合,均由searchByld()方法提供这个功能。具体代码如下:public class CategoryBiz ControlDB controlDB = null;public CategoryBiz() controlDB =
6、new ControlDB();public List searchById(int flag, String catid) String sql = ;List list = new ArrayList();if (flag = 0) sql = select * from category; else if (flag = 1) sql = select * from category where catid= + catid + ;System.out.println(sql);try list = controlDB.executeQueryCategory(sql); catch (
7、Exception e) e.printStackTrace();return list; (5)编写封装与数据库操作的ControlDB类。 (6)编写main.jsp页面,它用来显示大类别数据。main.jsp页面的部分代码如下:$ 运行Tomcat,执行此部分操作,最终效果如图所示:2、小类别显示,完成步骤同大类别显示运行Tomcat,执行此部分操作,最终效果如图所示:3、商品显示,完成步骤同大类别显示运行Tomcat,执行此部分操作,最终效果如图所示:4、添加商品到购物车在商品的列表页面提供了添加到购物车的链接。单击Add to Cart链接可以把与之对应的商
8、品添加入购物车中。要完成这个过程,需要执行一下步骤:(1)设置链接,为商品添加链接,在商品上创建链接的代码如下: (2)设置配置文件,在web.xml中添加如下代码:ItemServletorg.bzc.jpetstore.servlets.ItemServletItemServlet/item.do(3)在src目录的orgbzcjpetstoreservlets文件夹中新建名为ProductServlet的类,Servlet本身并没有处理业务数据,而是调用ItemBiz类的相关方法操作,具体代码如下:public class ProductServlet extends HttpServl
9、et 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 ServletExc
10、eption, IOException String path = request.getParameter(path);HttpSession session = request.getSession();List listProduct = new ArrayList();ProductBiz productbiz = new ProductBiz();ItemBiz itembiz = new ItemBiz();String tourl = ;if (show.equals(path) String productId = request.getParameter(productId)
11、;try List itemList = itembiz.searchByproductId(productId);Product product = (Product) productbiz.searchById(1, productId).get(0);session.setAttribute(itemList, itemList);session.setAttribute(product, product); catch (Exception e) e.printStackTrace();tourl = /catalog/Product.jsp; else listProduct = p
12、roductbiz.searchById(0, );tourl = index.html;session.setAttribute(listProduct, listProduct);request.getRequestDispatcher(tourl).forward(request, response);(4)编写Cart.jsp页面,来显示购物车中的商品项数据,Cart.jsp页面的部分代码如下:<< Main MenuShopping Cart Item ID Product ID Description In Stock? Quantity List Price Tota
13、l Cost Your cart is empty. $cartitem.item.itemid $ductid $cartitem.item.attr1 $cartitem.item.attr2 $cartitem.item.attr3 $cartitem.item.attr4 $cartitem.item.attr5 $ $cartitem.inStock $cartitem.item.listprice $cartitem.total Sub Total: $cart.subTotal 运行Tomcat,
14、执行此部分操作,最终效果如图所示:5、购物车中商品的管理在商品的列表页面提供了更改商品数量的输入框,用户可以更改数量,然后单击updatecart链接,完成更新购物车的操作,当操作执行完成后,返回本页面。单击remove链接可以把与之对应的商品从购物车中删除。(1)设置链接。如果用户执行“删除”操作,代码设置为:如果用户执行“修改”操作,将提交表单代码设置为:(2)设置配置文件。(3)在ItemServlet类中添加处理修改和删除功能的代码,具体如下:/获取商品标号String workingItemId = request.getParameter(itemId);Cart cart = n
15、ull;CartItem cartitem = null;/应该有个错误信息页跳转if (session.getAttribute(cartItems) = null) cart = new Cart(); else cart = (Cart) session.getAttribute(cart);/如果购物车中存在此商品,删除if (cart.containsItemId(workingItemId) cart.incrementQuantityByItemId(workingItemId); else Item item = (Item) itembiz.searchById(1, wor
16、kingItemId).get(0);cart.addItem(item, true);List cartItems = cart.getCartItemList();session.setAttribute(cartItems, cartItems);session.setAttribute(cart, cart);tourl = /cart/Cart.jsp; else if (removeItemFromCart.equals(path) String workingItemId = request.getParameter(workingItemId);Cart cart = null
17、;CartItem cartitem = null;/ 应该有个错误信息页跳转if (session.getAttribute(cartItems) = null) tourl = /cart/Cart.jsp;request.getRequestDispatcher(tourl).forward(request, response); List cartItems = cart.getCartItemList();session.setAttribute(cartItems, cartItems);session.setAttribute(cart, cart);tourl = /cart/
18、Cart.jsp; else if (updateCartQuantities.equals(path) Cart cart = null;CartItem cartitem = null;if (session.getAttribute(cartItems) = null) tourl = /cart/Cart.jsp;request.getRequestDispatcher(tourl).forward(request, response); else cart = (Cart) session.getAttribute(cart);List cartItem = cart.getCartItemList();/ 定义一个map来接收页面上传来的所有值Map parameterMap = new HashMap();for (int i = 0; i cartItem.size(); i+) String key = cartItem.get(i).getItem().getItemid();String value = request.getParameter(quantity + key);System.out.println(value + *);parameterMap
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 环保项目管理师面试题及答案
- 人力资源行业数字化转型调查报告
- 会计招聘真题及答案
- 公务员面试罗崧面试题及答案
- 海信集团招聘笔试题及答案
- 公务员面试考生疫情防控面试题及答案
- 国家能源集团招聘题库及答案
- 国机集团校招笔试题及答案
- 公务员考试思考试题及答案
- 公务员考试视力试题及答案
- 新生儿溢奶与吐奶护理要点
- 护理求职展示
- 建筑行业项目经理职业规划
- 高中选科规划课件
- 2025年互联网信息审核员考试题库及答案
- 2025年乡村振兴面试题及答案
- 2025年《新课程标准解读》标准课件
- 2024年普通高中学业水平选择性考试(福建卷)物理试题含答案
- 交流发言:深入实施数字化转型条件下税费征管“强基工程”推动县税务局工作高质量发展
- 1与食品经营相适应的操作流程
- 高考数学专项复习:导数压轴大题归类(解析版)
评论
0/150
提交评论