我学我会网上订餐系统 与在线书店类似_第1页
我学我会网上订餐系统 与在线书店类似_第2页
我学我会网上订餐系统 与在线书店类似_第3页
我学我会网上订餐系统 与在线书店类似_第4页
我学我会网上订餐系统 与在线书店类似_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、一SRCConnectionManagerJNDI/* 通用数据库连接操作类* author jp* date 2012-03-31*/public class ConnectionManagerJNDI public Connection conn=null;public PreparedStatement pStmt=null;public ResultSet rs=null;/* 取得连接的方法*/public void getConnection()tryContext ic=new InitialContext();DataSource ds=(DataSource)ic.looku

2、p("java:comp/env/jdbc/restrant"); conn=ds.getConnection();catch(Exception ex)ex.printStackTrace();/* 关闭所有数据库操作对象的方法*/public void closeAll()tryif(rs!=null)rs.close();rs=null; if(pStmt!=null) pStmt.close(); pStmt=null; if(conn!=null) conn.close(); conn=null; catch(Exception ex) ex.printStack

3、Trace(); FoodDao/* 餐品数据库操作类* author jp* date 2012-03-31*/public class FoodDao extends ConnectionManagerJNDI /* 取得所有的餐品信息列表的方法* return*/public List<FoodInfo> getAllFoodList() List<FoodInfo> list=null;trysuper.getConnection();String sql="select * from foodInfo" pStmt=conn.prepare

4、Statement(sql); rs=pStmt.executeQuery();list=new ArrayList<FoodInfo>(); while(rs.next()FoodInfo food=new FoodInfo(); food.setFoodID(rs.getString("foodID"); food.setFoodName(rs.getString("foodName"); food.setFoodPrice(rs.getDouble("foodPrice"); food.setFoodImage(rs

5、.getString("foodImage"); food.setRemarkPass(rs.getString("remark"); food.setDescription(rs.getString("description"); list.add(food); catch(Exception ex) ex.printStackTrace(); finally super.closeAll(); return list;OrderDao/* 订单处理数据库操作类* author 江萍* date 2012-03-31*/public

6、 class OrderDao extends ConnectionManagerJNDI /* 添加订单的方法* param order 订单实体类实例* return*/public int addFoodOrder(OrderBean order)int iResult=0;trysuper.getConnection();String sql="insert into foodOrderInfo(customerName,address,zipCode, "+"telePhone,movePhone,notice,totalPrice) values(?,

7、?,?,?,?,?,?)" pStmt=conn.prepareStatement(sql); pStmt.setString(1, order.getCustomerName(); pStmt.setString(2, order.getAddress(); pStmt.setString(3, order.getZipCode() ); pStmt.setString(4, order.getTelephone(); pStmt.setString(5, order.getMovePhone(); pStmt.setString(6, order.getNotice(); pSt

8、mt.setDouble(7, order.getTotalPrice(); iResult=pStmt.executeUpdate(); catch(Exception ex) ex.printStackTrace(); finally super.closeAll(); return iResult;UserDao/* 用户信息数据库操作类* author 江萍* date 2012-03-31*/public class UserDao extends ConnectionManagerJNDI /* 检查登录方法* param loginName 用户名* param loginPas

9、s 密码* return*/public UserInfo chkLogin(String loginName,String loginPass)UserInfo user=null;trysuper.getConnection();String sql="select * from userInfo where loginName=? and loginPass=?" pStmt=conn.prepareStatement(sql);pStmt.setString(1, loginName);pStmt.setString(2, loginPass); rs=pStmt.

10、executeQuery(); while(rs.next() user=new UserInfo(); user.setUseID(rs.getInt("userID"); user.setLoginName(rs.getString("loginName"); user.setLoginPass(rs.getString("loginPass"); catch(Exception ex)ex.printStackTrace();finallysuper.closeAll();return user;CartItempublic c

11、lass CartItem private FoodInfo food;private int quantity;public FoodInfo getFood() return food;public void setFood(FoodInfo food) this.food = food;public int getQuantity() return quantity;public void setQuantity(int quantity) this.quantity = quantity; public CartItem() super(); / TODO Auto-generated

12、 constructor stub public CartItem(FoodInfo food, int quantity) super(); this.food = food; this.quantity = quantity; FoodInfopublic class FoodInfo private String foodID;private String foodName;private String remarkPass;private double foodPrice;private String description;private String foodImage;publi

13、c String getFoodID() return foodID;public void setFoodID(String foodID) this.foodID = foodID;public String getFoodName() return foodName;public void setFoodName(String foodName) this.foodName = foodName;public String getRemarkPass() return remarkPass;public void setRemarkPass(String remarkPass) this

14、.remarkPass = remarkPass; public double getFoodPrice() return foodPrice; public void setFoodPrice(double foodPrice) this.foodPrice = foodPrice; public String getDescription() return description; public void setDescription(String description) this.description = description; public String getFoodImage

15、() return foodImage; public void setFoodImage(String foodImage) this.foodImage = foodImage;OrderBeanpublic class OrderBean private int orderID;private String customerName; private String address; private String zipCode; private String telephone; private String movePhone;private String notice; privat

16、e double totalPrice; public int getOrderID() return orderID; public void setOrderID(int orderID) this.orderID = orderID; public String getCustomerName() return customerName; public void setCustomerName(String customerName) this.customerName = customerName; public String getAddress() return address;

17、public void setAddress(String address) this.address = address; public String getZipCode() return zipCode; public void setZipCode(String zipCode) this.zipCode = zipCode; public String getTelephone() return telephone; public void setTelephone(String telephone) this.telephone = telephone; public String

18、 getMovePhone() return movePhone; public void setMovePhone(String movePhone) this.movePhone = movePhone; public String getNotice() return notice; public void setNotice(String notice) this.notice = notice; public double getTotalPrice() return totalPrice; public void setTotalPrice(double totalPrice) t

19、his.totalPrice = totalPrice; UserInfopublic class UserInfo private int useID;private String loginName;private String loginPass;public int getUseID() return useID;public void setUseID(int useID) this.useID = useID;public String getLoginName() return loginName;public void setLoginName(String loginName

20、) this.loginName = loginName;public String getLoginPass() return loginPass;public void setLoginPass(String loginPass) this.loginPass = loginPass;CharacterFilterpublic class CharacterFilter implements Filter public void destroy() / TODO Auto-generated method stubpublic void doFilter(ServletRequest re

21、quest, ServletResponse response, FilterChain chain) throws IOException, ServletException chain.doFilter(request, response);public void init(FilterConfig arg0) throws ServletException / TODO Auto-generated method stubLoginFilterpublic class LoginFilter extends HttpServlet implements Filter public voi

22、d doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException HttpServletRequest req=(HttpServletRequest)request;HttpServletResponse res=(HttpServletResponse)response;UserInfo user=(UserInfo)req.getSession().getAttribute("userNow");if(u

23、ser=null)String path=req.getContextPath();StringbasePath=req.getScheme()+":/"+req.getServerName()+":"+req.getServerPort()+path+"/" res.sendRedirect(basePath+"/login.jsp");elsechain.doFilter(request, response);public void init(FilterConfig arg0) throws ServletE

24、xception / TODO Auto-generated method stubCartServlepublic class CartServlet extends HttpServlet /* Constructor of the object.*/public CartServlet() super();/* Destruction of the servlet. <br>*/public void destroy() super.destroy(); / Just puts "destroy" string in log/ Put your code

25、here/* The doGet method of the servlet. <br>* This method is called when a form has its tag value method equals to get. * param request the request send by the client to the server* param response the response send by the server to the client* throws ServletException if an error occurred* thro

26、ws IOException if an error occurred*/public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request,response);/* The doPost method of the servlet. <br>* * This method is called when a form has its tag value method equals to post.

27、 * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) thro

28、ws ServletException, IOException HttpSession session=request.getSession(); FoodInfo foodToAdd=(FoodInfo)session.getAttribute("food"); CartItem item=null; List<CartItem> cart=(List<CartItem>)session.getAttribute("cart"); List<CartItem> cartNew=new ArrayList<Ca

29、rtItem>(); if(cart=null) cart=new ArrayList<CartItem>(); item=new CartItem(foodToAdd,1); cartNew.add(item); else boolean b=false; for(CartItem itemNow:cart) if(itemNow.getFood().equals(foodToAdd) b=true; itemNow=new CartItem(foodToAdd,itemNow.getQuantity()+1); cartNew.add(itemNow); /判断购物车中是

30、否存在当前要添加的这个条目 if(!b)/不存在的情况 item=new CartItem(foodToAdd,1); cartNew.add(item); session.setAttribute("cart",cartNew); response.sendRedirect("jsp/showCart.jsp"); /* * Initialization of the servlet. <br>* * throws ServletException if an error occurs */ public void init() throw

31、s ServletException / Put your code here FoodServletpublic class FoodServlet extends HttpServlet /* 不懂事什么意思,有什么用途* serialVersionUID 用来表明类的不同版本间的兼容性 */private static final long serialVersionUID=1L; /* Constructor of the object.*/public FoodServlet() super();/* Destruction of the servlet. <br>*/p

32、ublic void destroy() super.destroy(); / Just puts "destroy" string in log / Put your code here /* * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * par

33、am response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request,response); /* * The do

34、Post method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws

35、IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException HttpSession session=request.getSession(); FoodDao foodDao=new FoodDao(); List<FoodInfo> list=foodDao.getAllFoodList(); session.setAttribute(&quo

36、t;list", list); response.sendRedirect("jsp/index.jsp"); /* * Initialization of the servlet. <br> * * throws ServletException if an error occurs */public void init() throws ServletException / Put your code here LoginServletpublic class LoginServlet extends HttpServlet /*/private

37、static final long serialVersionUID = 1L;/* Constructor of the object.*/public LoginServlet() super();/* Destruction of the servlet. <br>*/public void destroy() super.destroy(); / Just puts "destroy" string in log / Put your code here/* The doGet method of the servlet. <br> * *

38、This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */ public v

39、oid doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request, response); /* * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * param request the request send by t

40、he client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException HttpSes

41、sion session=request.getSession(); String loginName=request.getParameter("loginName"); String loginPass=request.getParameter("loginPass"); UserDao userDao=new UserDao(); UserInfo user=userDao.chkLogin(loginName, loginPass); if(user=null) /登录失败 response.sendRedirect("login.js

42、p"); else /登录成功 session.setAttribute("userNow", user); response.sendRedirect("FoodServlet"); /* * Initialization of the servlet. <br> * * throws ServletException if an error occurs */ public void init() throws ServletException / Put your code here OrderServletSuppressW

43、arnings("serial")public class OrderServlet extends HttpServlet /* Constructor of the object.*/public OrderServlet() super();/* Destruction of the servlet. <br>*/public void destroy() super.destroy(); / Just puts "destroy" string in log / Put your code here/* The doGet metho

44、d of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException

45、 if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request, response); /* * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * pa

46、ram request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws Serv

47、letException, IOException HttpSession session=request.getSession(); OrderBean order=new OrderBean(); order.setCustomerName(request.getParameter("customerName"); order.setAddress(request.getParameter("address"); order.setZipCode(request.getParameter("zipCode"); order.set

48、Telephone(request.getParameter("telephone"); order.setMovePhone(request.getParameter("movePhone"); order.setNotice(request.getParameter("notice"); order.setTotalPrice(Double.parseDouble(request.getParameter("totalPrice"); OrderDao orderDao=new OrderDao(); orde

49、rDao.addFoodOrder(order); session.invalidate(); response.sendRedirect("login.jsp"); /* * Initialization of the servlet. <br> * * throws ServletException if an error occurs */ public void init() throws ServletException / Put your code here 二Webroot1JSP文件夹下<%String path = request.ge

50、tContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html><head><title>My JSP 'index.jsp' startin

51、g page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,ke

52、yword2,keyword3"><meta http-equiv="description" content="This is my page"><link rel="stylesheet" href="./css/styles.css" type="text/css" /><script language="javascript" type="text/javascript" src="js/ja

53、vaScript.js"></script> </head><BODY leftMargin="0" topMargin="0" marginheight="0" marginwidth="0"> <jsp:include page="./BodyTop.jsp" /><TABLE cellSpacing="0" cellPadding="0" width="776"

54、 align="center" border="0"> <TBODY><TR vAlign="top"><TD width="181" background="images/002.gif"><jsp:includepage="./BodyLeft.jsp" /></TD><TD><jsp:include page="./BodyInnerTop.jsp" /><

55、;TABLE cellSpacing="0" cellPadding="0" width="80%" align="center" border="0"><TBODY><TR><TD><TABLE cellSpacing="1" cellPadding="1" width="100%" align="center"bgColor="#c0c0c0"

56、border="0"><TBODY><TR bgColor="#dadada"><TD width="100%" align="center">我学我会网上点餐系统用户请直接登录</TD></TR></TBODY></TABLE><BR></TD></TR></TBODY></TABLE><%- 内容区域开始 -%><c:forEach var=&q

57、uot;obj" items="$list" varStatus="i"><c:if test="$param.foodID=obj.foodID"><c:set var="food" value="$obj" scope="session"></c:set></c:if></c:forEach><CENTER><table cellSpacing="0" cel

58、lPadding="0" width="500" align="center"> <tr><td align="center"><img src="./images/$food.foodImage " width="190" height="190"/><br/><strong>编号:$food.foodID </strong></td><td><s

59、trong>菜名:<font color="#8B008B"size="4">$food.foodName </font></strong><br><br><strong>价格:<font color="#EA0000" size="4">$food.foodPrice </font>元/份</strong><br><br><strong>$food.remarkPa

60、ss </strong><br><br><strong>描述:$food.description </strong><br><br><center><form action="./CartServlet" method="post"><input type="image" src="./images/buy_cn.gif"/></form></center></td&

61、gt;</tr></table></CENTER><%- 内容区域结束 -%></TBODY></TABLE><jsp:include page="./BodyFoot.jsp" /></BODY></html>2<%String path = request.getContextPath();String basePath = request.getScheme()+":/"+request.getServerName()+":&

62、quot;+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html><head><base href="<%=basePath%>"><title>我学我会网上订餐系统-订单处理页面</title><meta http-equiv="pragma" content="n

63、o-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" conte

64、nt="This is my page"><link rel="stylesheet" type="text/css" href="<%=basePath%>/css/styles.css"><script language="javascript" type="text/javascript" src=<%=basePath%>/js/javaScript.js></script></head><BODY leftMargin="0" topMargin="0" marginheight="0" marginwidth="0"> <jsp:include page="./BodyTop.jsp" /><TABLE cellSpacing="0" cellPadding="0" width="776" ali

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论