java web 程序---购物车选商品,购买,付款

思路:1.有一个单选按钮,让我们选择商品  

     2.购买的物品及 数量清算

        3.付款

 

我的界面:

home.jsp

 <body>
  <center>
  选择您购买的商品
  <br/><br/><br/><br/>
  	<form action="test.jsp">
	汽车:<img src="a.jpg" width="100" high="50"/><input type="checkbox" name="a" value="b1"/> <br/>
	电脑:<img src="b.jpg" width="100" high="50"/><input type="checkbox" name="a" value="b2"/><br/>
	手机:<img src="c.jpg" width="100" high="50"/><input type="checkbox" name="a" value="b3"/><br/>
	<input type="submit" value="提交"/>
	</form>
  
  
  </center>

  </body>

  test.jsp

  
  <body>
  
    <%
   		HashMap map1=(HashMap)session.getAttribute("map");
    		if(map1==null){
    			
    		 map1=new HashMap();
    		map1.put("qiche",0);
    		map1.put("diannao",0);
    		map1.put("shouji",0);
    		session.setAttribute("map",map1);
    
    		}
    		
    		String str[]=request.getParameterValues("a");
    		for(int i=0;i<str.length;i++){
    			if(str[i].equals("b1")){
    			int number1=(Integer)(map1.get("qiche"));
    			map1.put("qiche",number1=number1+1);
    			}else if(str[i].equals("b2")){
    			int number2=(Integer)map1.get("diannao");
    			map1.put("diannao",number2=number2+1);
    			}else if(str[i].equals("b3")){
    			int number3=(Integer)(map1.get("shouji"));
    			map1.put("shouji",number3=number3+1);
    			}
    			session.setAttribute("map",map1);
    		}
    
     %>
     您购买的东西:
    汽车: <%=map1.get("qiche") %><br/>
     电脑:<%=map1.get("diannao") %><br/>
     手机:<%=map1.get("shouji") %><br/>
   继续购买:<a href="home.jsp">继续购买</a>
     去结账:<a href="pay.jsp">结账</a>
  </body>

  pay.jsp

  <body>
	<%
	 	HashMap map=(HashMap)session.getAttribute("map");
	 	int a=(Integer)map.get("qiche");
	 	int b=(Integer)map.get("diannao");
	 	int c=(Integer)map.get("shouji");
	 	int count=a*1000+b*232+c*43;
	
	 %>
	 应该付款:<%=count %>元
  </body>

  

   

转载于:https://www.cnblogs.com/langlove/p/3708040.html

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值