思路: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>