//login.jsp
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <html> 3 <head> 4<title>简易购物网站</title> 5 </head> 6 7 <body> 8<center><h2>登录页面</h2></center> 9<p>输入您的个人信息:10<form action="shop.jsp" method="post"name=form>11 <input type="text"name="user" ><br><br>12 <input type="radio" name="Kind" value="普通会员"checked=true>普通会员13 <input type="radio" name="Kind" value="VIP">VIP(享有九折优惠)<br><br>14 <input type="submit" value="进入商店" name="submit">15 </form>16 </body>17 </html>
//shop.jsp
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <html> 3 <head> 4<title>简易购物网站</title> 5 </head> 6 7 <body> 8<center><h2>商品选择页面</h2></center> 9<%10 request.setCharacterEncoding("UTF-8");11 String s=request.getParameter("user");12 session.setAttribute("name", s);13 String k=request.getParameter("Kind");14 session.setAttribute("Kind", k);15 out.println("欢迎"+k+":"+s+"来到本网站购物!");16%>17 <p>请选择要购买的商品:18<form action="account.jsp" method="post"name=form>19 <input type="checkbox"name="Goods" value="风衣">风衣50020 <input type="checkbox"name="Goods" value="牛仔裤">牛仔裤40021 <input type="checkbox"name="Goods" value="运动鞋">运动鞋600<br><br>22 <input type="submit" value="去结账" name="submit">23</form>24 </body>25 </html>
//account.jsp
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <html> 3 <head> 4<title>简易购物网站</title> 5 </head> 6 7 <body> 8<center><h2>结账页面</h2></center> 9<%10 request.setCharacterEncoding("UTF-8");11 String inst[]=request.getParameterValues("Goods");12 session.setAttribute("goodsN", inst.length);13 for(int i=0;i<inst.length;i++)14 {15 session.setAttribute("goods"+i, inst[i]);16 }17 String customerKind=(String)session.getAttribute("kind");18 String customerName=(String)session.getAttribute("name");19 Double sum=0.0;20 String customerGoods="";21 String Info="";22 int num=Integer.parseInt(String.valueOf(session.getAttribute("goodsN")));23 for(int i=0;i<num;i++)24 {25 customerGoods+=session.getAttribute("goods"+i)+"";26 if(String.valueOf(session.getAttribute("goods"+i)).equals("风衣"));27 sum+=500;28 if29 (String.valueOf(session.getAttribute("goods"+i)).equals("牛仔裤"))30 sum+=400;31 else 32 sum+=600; 33 }34 if(customerKind.equals("VIP"))35 {36 sum=sum*0.9;37 Info="您享有九折优惠,打折后的总金额是:";38 }39 else40 Info="总金额是:";41 42%>43 <p><%=customerKind %>的姓名是:<%=customerName %>44 <p>选择购买的商品是<%=customerGoods%>45 <p><%=Info %>46 <p>欢迎您下次光临!47 48 </body>49 </html>