1、本商城主要利用javaservlet技术进行开发,有很强的逻辑性、可扩展性,便于维护。商城界面设计主要实用了CSS,美化了店面。其次本商城设计还使用了JSP技术、JDBC技术、JavaBean技术、css。2.1 系统结构图图2.1 系统整体框图2.2系统功能分析新品上市模块:在首页框架中显示新品列表畅销商品模块:在首页框架中显示畅销列表购物车模块:显示已点击购买但没结账的商品结账模块:直接显示当前订单查看商品信息模块:显示当前商品详细信息商品分类模块:分类显示商品全部商品模块:显示商品列表查询商品模块:搜寻商品,显示商品信息用户注册模块:实现用户注册统功能分析第三章 详细设计3.1数据库设计
2、 商品表(shoe)用户表(user)用户订单表(orderinfo)3.2 商品模块实现 3.2.1 模块功能实现和关键代码说明先由JSP页面发出请求调用mypack包下GetshoeServlet,调用里面的 doGet方法,然后调用db.executeQuery(sql)方法,查询数据库,查到热销商品的列表,保存进requeset对象的resault变量里,然后通过调用取出其中的值,显示到主页面。商品查询模块按商品ID、关键词查询,商品显示模块使用同样方法根据不同条件查询数据库。主要代码如下: protected void doGet(HttpServletRequest req, Ht
3、tpServletResponse resp) throws ServletException, IOException req.setCharacterEncoding(utf-8); String typeId = req.getParameter(typeId String shoeId = req.getParameter(shoeId String keyword = req.getParameter(keyword String sql = select * from shoe; String sql1 = select * from shoe where typeId = ? S
4、tring sql2 = select * from shoe where shoeId = ? List shoelist = new ArrayList(); HttpSession session = req.getSession(); BookDB db = null; CachedRowSet result = null; try db = new BookDB(); if(typeId != null) if(typeId.equals(0) result = db.executeQuery(sql); else result = db.executeQuery(sql1, typ
5、eId); while(result.next() Shoe shoe = new Shoe(); shoe.setType(result.getString(1); shoe.setShoeId(result.getInt(2); shoe.setName(result.getString(3); shoe.setPrice(result.getFloat(4); shoelist.add(shoe); session.setAttribute(shoelist, shoelist); resp.sendRedirect(req.getContextPath()+/catalog.jsp i
6、f(shoeId ! result = db.executeQuery(sql2, Integer.parseInt(shoeId); if(result.next() Shoe shoeDetail = new Shoe(); shoeDetail.setType(result.getString(1); shoeDetail.setShoeId(result.getInt(2); shoeDetail.setName(result.getString(3); shoeDetail.setPrice(result.getFloat(4); shoeDetail.setSale_amount(
7、result.getInt(5); session.setAttribute(shoedetail, shoeDetail);/shoedetail.jsp if(keyword ! result = db.executeQuery(sql); if(result.getString(3).contains(keyword) Shoe shoe = new Shoe(); shoe.setType(result.getString(1); shoe.setShoeId(result.getInt(2); shoe.setName(result.getString(3); shoe.setPri
8、ce(result.getFloat(4); shoelist.add(shoe); catch (Exception e) / TODO Auto-generated catch block e.printStackTrace(); 3.3 用户注册/登录模块实现3.3.1 模块功能实现和关键代码说明Begin调用/ARMY-SHOES/UserLoginServlet和UserRegistServlet 返回查询/更新数据库显示regist.jsp/login.jsp先由JSP页面发出请求调用mypack包下UserRegistServlet/UserLoginServlet,调用里面的
9、doGet方法,然后调用db.executeQuery(sql1, username, password)方法,更新数据库。登录(UserLoginServlet):HttpSession session = req.getSession(); result = db.executeQuery(sql1, username, password); if (result.next() user = new User(); user.setUsername(result.getString(1); user.setPassword(result.getString(2); user.setMail
10、(result.getString(3); user.setTel(result.getString(4);user, user); resp.sendRedirect(req.getContextPath() + /index.jsp else /login.jsp?statu=no注册(UserRegistServlet): String username = req.getParameter(username String password = req.getParameter(password String mail = req.getParameter(mail String tel
11、 = req.getParameter(telselect * from user where username = ?insert into user values(?, ?) BookDB db; result = db.executeQuery(sql1, username); if(result.next()/regist.jsp? else db.executeUpdata(sql2, username, password, mail, tel);statu=ok3.4 购物车模块实现 3.4.1 模块功能实现和关键代码说明调用mypack包下 ShoppingCart里的add()
12、/remove()/getTotal()方法 返回item查询数据库显示showCart.jsp图3.1 购物车模块流程图先由JSP页面发出请求调用org.action包下的findId方法,findId调用DaoImpl包里的findOrderById,把得到的结果,保存到session里取名order1通过orderdetail里取变量得到这个值,显示到主页面。主要代码如下:Add()方法: public synchronized void add(String shoeId, Shoe shoe) if(items.containsKey(shoeId) ShoppingCartItem
13、 scitem = (ShoppingCartItem) items.get(shoeId); scitem.incrementQuantity(); else ShoppingCartItem newItem = new ShoppingCartItem(shoe); items.put(shoeId, newItem); numberOfItems+;Remove()方法: public synchronized void remove(String shoeId) scitem.decrementQuantity(); if(scitem.getQuantity() = 0) items
14、.remove(shoeId); numberOfItems-;Gettotal()方法:public synchronized double getTotal() double amount = 0.0; for(Iterator i = getItems().iterator(); i.hasNext(); ) ShoppingCartItem item = (ShoppingCartItem) i.next(); Shoe shoe = (Shoe) item.getItem(); amount += item.getQuantity() * shoe.getPrice(); retur
15、n roundOff(amount); private double roundOff(double x) long val = Math.round(x*100); / cents return val/100.0; public synchronized void clear() items.clear(); numberOfItems = 0;3.5 结算功能模块从showcart.jsp转到cashier.jsp,调用HandleOrderServlet的db.buyBooks(cart)方法和db.executeUpdata( )方法更新数据库。String sql = insert
16、 into orderinfo values(? db.buyBooks(cart); db.executeUpdata(sql, orderId,username, cardname, cardnum, payment); resp.sendRedirect(req.getContextPath()+/cashier.jsp?makeorder=ok.printStackTrace();第四章 总结【技术总结】1.一个Servlet往往对应了不同的操作,一个对象的增删改查,都放在了一个Servlet里面实现,这样设计可有效减少Servlet数量;2.对于网页页面效果要求较高的时候,多采用JSP来编写,对于后台处理要求较高时,多采用Servlet。3.尽量使用和数据库版本一致的驱动,否则jdbc连接可能不正常;4. 在编写样式表之前一定要注意CSS文档的编码类型一定要和HTML文档的字符集类型一致。【心得体会】通过这次课程设计,使我加深了对javaweb应用结构的理解,掌握了javaweb应用设计的流程及各个模块间协同关系,学会了使用css美化个人设计。
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2