网上购物系统设计与实现

时间:2015-12-28 10:55:17
【文件属性】:

文件名称:网上购物系统设计与实现

文件大小:1.29MB

文件格式:DOC

更新时间:2015-12-28 10:55:17

网上购物

网上购物系统设计和实现课程设计 四、程序关键代码及效果图 1、过滤器代码:[只要doFilter()方法] (1)adminfilter.java: HttpServletRequest requ=(HttpServletRequest)req; res.setCharacterEncoding("gb18030"); requ.setCharacterEncoding("gb18030"); HttpSession session=requ.getSession(); if(session.getAttribute("admin")==null){ PrintWriter out=res.getWriter(); out.println("[removed]"); out.println("alert('您还没有登录!');"); out.println("[removed].href='../login_admin.jsp';"); out.println("[removed]"); }else{ chain.doFilter(req, res); } (2)userfilter.java: HttpServletRequest requ=(HttpServletRequest)req; res.setCharacterEncoding("gb18030"); requ.setCharacterEncoding("gb18030"); HttpSession session=requ.getSession(); if(session.getAttribute("uname")==null){ PrintWriter out=res.getWriter(); out.println("[removed]"); out.println("alert('您还没有登录!');"); out.println("[removed].href='../login.html';"); out.println("[removed]"); }else{ chain.doFilter(req, res); } (3)Encodingfilter.java: HttpServletRequest request=(HttpServletRequest)req; request.setCharacterEncoding("gb18030"); HttpServletResponse response=(HttpServletResponse)res; response.setCharacterEncoding("gb18030"); chain.doFilter(req, res); } 2、Servlet代码:[只要doPost()或doGet()方法] (1)add.java: response.setContentType("text/html"); request.setCharacterEncoding("gb18030"); HttpSession session=request.getSession(); CartBean cb=new CartBean(); Vector cart =(Vector)session.getAttribute("cart"); String id=request.getParameter("id"); if(cart==null){ cart=new Vector(); } cart=cb.addCart(cart,id); session.setAttribute("cart",cart); response.sendRedirect("cart.jsp"); } (2)addproduct.java: PrintWriter out=response.getWriter(); Product p = new Product(); SmartUpload su = new SmartUpload(); su.initialize(this.getServletConfig(), request, response); su.setMaxFileSize(1024 * 1024 * 10); su.setAllowedFilesList("JPG,jpg,gif,GIF");


网友评论

  • 还不错,很有参考价值