jsp实验应用Servlet实现购物车讲解
AR技术增强现实购物体验 #生活常识# #科技应用#
jsp实验应用Servlet实现购物车讲解 jsp实验应用Servlet实现购物车讲解 jsp实验应用Servlet实现购物车讲解 应用 Servlet 实现购物车 详细实现过程 1、 创立封装商品信息的值 JavaBeanGoodsSingle package com.yxq.valuebean; public class GoodsSingle { private String name; //保存商品名称 private float price; //保存商品价格 private int num; //保存商品购置数量 public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } } 2、 创立工具 JavaBean MyTools 实现字符型数据转 换为整型及乱码办理 package com.yxq.toolbean; import java.io.UnsupportedEncodingException; public class MyTools { public static int strToint(String str){ //将 String 型数据 变换为 int 型数据的方法 if(str==null||str.equals()) str=0; int i=0; try{ i=Integer.parseInt(str); //把 str 变换成 int 种类的变量 }catch(NumberFormatException e){ // try-catch 就 是监察 try 中的语句 ,若是抛出 catch中声明的异常种类 i=0; e.printStackTrace(); //把 Exception 的详细信息打印出来 } return i; } public static String toChinese(String str){ //进行转码操作 的方法 if(str==null) str=; try { str=new String(str.getBytes(ISO-8859-1),gb2312); } catch (UnsupportedEncodingException e) { str=; e.printStackTrace(); } return str; } } 3、 创立购物车 JavaBean ShopCar 实现增加、删除, 购物车制作 package com.yxq.toolbean; package com.yxq.toolbean; import java.util.ArrayList; import com.yxq.valuebean.GoodsSingle; public class ShopCar { private ArrayList buylist=new ArrayList(); //用来储藏购置的商品 public void setBuylist(ArrayList buylist) { this.buylist = buylist; } /** * @ 功能 向购物车中增加商品 * @ 参数 single为 GoodsSingle类对象,封装了要增加的商 品信息 */ public void addItem(GoodsSingle single){ if(single!=null){ if(buylist.size()==0){ //若是 buylist 中不存在任何商品 GoodsSingle temp=new GoodsSingle(); temp.setName(single.getName()); temp.setPrice(single.getPrice()); temp.setNum(single.getNum()); buylist.add(temp); //储藏商品 } else{ //若是 buylist 中存在商品 int i=0; for(;ibuylist.size();i++){ //遍历 buylist 会集对象, 判断该会集中可否已经存在当前 要增加的商品 GoodsSingle temp=(GoodsSingle)buylist.get(i
网址:jsp实验应用Servlet实现购物车讲解 https://www.yuejiaxmz.com/news/view/237343
相关内容
jsp开发实用技巧servlet简单例子1
JSP家居管理系统pho64
jsp大学生心理健康检测咨询平台gps17
jsp青少年运动健身网站xl68g(程序+源码+数据库+调试部署+开发环境)
校园二手物品交易系统
校园二手商品交易网站的设计与实现
基于Java的在线购物系统的设计与实现
基于springboot的C2C二手交易系统的设计与实现(源码+论文)
基于JAVA的家庭财务管理系统的设计与实现毕业论文