好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

简单的购物车实现.pdf

6页
  • 卖家[上传人]:橙**
  • 文档编号:333325856
  • 上传时间:2022-09-01
  • 文档格式:PDF
  • 文档大小:46.24KB
  • / 6 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 简单的购物车实现这是我个人写的简单的Javaweb程序,简单的购物车实现以下为主要源程序代码/以下代码是一个简单的选购物品页面shop.html !-电视机 苹果 大米 酱油 台斤瓶袋 数量:价钱:元 名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 6 页 -简单的购物车实现 /这是一个简单的购物Servlet 程序package cn;import java.io.IOException;import java.io.PrintWriter;import java.util.Enumeration;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;public class Shop extends HttpServlet /*Constructor of the object.*/public Shop()super();/*Destruction of the servlet.*/public void destroy()super.destroy();/Just puts destroy string in log/Put your code here 名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 6 页 -简单的购物车实现/*The doGet method of the servlet.*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*/*The doPost method of the servlet.*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 IOException if an error occurred*/public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException /*response.setContentType(text/html);PrintWriter out=response.getWriter();HttpSession session=request.getSession(true);Goods s=new Goods();s.setGoods(request.getParameter(goods);s.setLei(request.getParameter(lei);s.setNumber(request.getParameter(number);s.setPrice(request.getParameter(price);session.setAttribute(request.getParameter(goods),s);System.out.println(session);Enumeration e=request.getAttributeNames();out.println();out.println(A Servlet);out.println();out.print(购物车);while(e.hasMoreElements()String name=e.nextElement();Goods g=(Goods)session.getAttribute(goods);out.print(商品名称:+g.getGoods()+);名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 6 页 -简单的购物车实现out.print(商品:+g.getLei()+);out.print(商品数量:+g.getNumber()+);out.print(商品价格:+g.getPrice()+);out.print();out.println(继续购物);out.println();out.println();out.flush();out.close();*/response.setContentType(text/html;charset=utf-8);request.setCharacterEncoding(utf-8);HttpSession session=request.getSession();String goods=request.getParameter(goods);String price=request.getParameter(price);String number=request.getParameter(number);String lei=request.getParameter(lei);Goods good=new Goods(goods,number,price,lei);session.setAttribute(good.toString(),good);/session.setAttribute(goods,good);PrintWriter out=response.getWriter();Enumeration e=session.getAttributeNames();while(e.hasMoreElements()String name=e.nextElement();Goods g1=(Goods)session.getAttribute(name);out.println(商品:+g1.getGoods()+);out.println(数量:+g1.getNumber()+g1.getLei()+);out.println(价格:+g1.getPrice()+);out.println();/out.println(单位:+g1.getLei()+);out.println();out.println(A Servlet);out.println();out.println(继续购物 );out.println();out.println();out.flush();名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 6 页 -简单的购物车实现out.close();/*Initialization of the servlet.*throws ServletException if an error occurs*/public void init()throws ServletException /Put your code here /以下代码是声名商品的属性。

      package cn;public class Goods private String goods;private String number;private String price;private String lei;public Goods()public Goods(String goods,String number,String price,String lei)this.goods=goods;this.number=number;this.price=price;this.lei=lei;public String getGoods()return goods;public void setGoods(String goods)this.goods=goods;public String getNumber()return number;public void setNumber(String number)this.number=number;名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 6 页 -简单的购物车实现 public String getPrice()return price;public void setPrice(String price)this.price=price;public String getLei()return lei;public void setLei(String lei)this.lei=lei;public String toString()return goods+number+price+lei;/以下代码为Servlet 程序在 web.xml 下的配置,这个可以直接创建servlet 类直接自动生成 This is the description of my J2EE component This is the display name of my J2EE component Shop cn.Shop Shop/servlet/Shop index.jsp 名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 6 页 -。

      点击阅读更多内容
      相关文档
      初中英语新人教版八年级上册Unit 4 Amazing Plants and Animals默写练习(汉译英+英译汉+音标写英汉)(附参考答案)(2025秋).doc 高中英语2026届高考完形填空常考形容词和副词(共107个).doc 初中英语新人教版八年级上册Unit1—Unit3单元写作指导(写作任务+思路点拨+参考范文】.doc 初中英语2026届中考单词词性和固定搭配解析(名词+动词+形容词+副词+介词+连词).doc 小学科学新教科版三年级上册全册思维导图(共三个单元)(2025秋).doc 初中英语新人教版八年级上册Unit 2 Home Sweet Home单词转化和练习.doc 初中英语2026届中考语法基础知识汇总(共七部分).doc 初中英语新人教版八年级上册Unit 6 Plan for yourself默写练习(汉译英+英译汉+音标写英汉)(附参考答案)(2025秋).doc 初中英语新人教版八年级上册Unit3—Unit4重点短语(2025秋).doc 初中英语2026届中考人教版新课标高频短语汇总(动词短语+介词短语+固定搭配与习语).doc 初中英语新译林版八年级上册Unit 1 Friendship课文解析(A部分)(2025秋).doc 小学英语新人教版PEP四年级上册unit5—unit6知识点(2025秋).doc 初中英语新外研版八年级上册 Unit 1 This is me.语法知识现在完成时讲解与练习.doc 初中英语新译林版八年级上册Unit 1 Friendship课文解析(B部分)(2025秋).doc 初中英语新人教版八年级上册Unit 1 Happy Holiday单词转化和练习.doc 初中英语2026届中考作文对话描写高分句分类汇总(科学现象+人际交往+立秋).doc 初中英语2026届中考主要时态句型(含例句)(共十类100个).doc 初中英语2026届中考基础词汇(共28类400个).doc 初中英语2026届中考作文高分素材(常用句式+活用句型+名言谚语+关系连词).doc 初中英语新译林版八年级上册Unit 1 Friendship语法和写作(2025秋).doc
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.