标签:box import amp 购物车 ssi param 一个 images logs
设计一个简单的购物车程序。该案例提供了两种不同类型的商品,不同类型的商品需要在不同的网页上浏览,并添加到购物车中,最后显示购物车中所选购的商品。
meat.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head><title>肉类商品页面</title>
</head>
<body>
<%request.setCharacterEncoding("UTF-8");
if(request.getParameter("c1")!=null)
session.setAttribute("s1", request.getParameter("c1"));
if(request.getParameter("c2")!=null)
session.setAttribute("s2", request.getParameter("c2"));
if(request.getParameter("c3")!=null)
session.setAttribute("s3", request.getParameter("c3"));
%>
各种肉大甩卖,一律十块钱:<br>
<form action="meat.jsp" method="post"></form>
<p><input type="checkbox" name="c1" value="猪肉">猪肉
<input type="checkbox" name="c2" value="牛肉">牛肉
<input type="checkbox" name="c3" value="羊肉">羊肉
</p>
<p><input type="submit" name="B1" value="提交">
<a href="sport.jsp">买点别的</a>
<a href="buy.jsp">查看购物车</a>
</p>
</body>
</html>
sport.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head><title>球类购买页面</title></head>
<body>
<%request.setCharacterEncoding("UTF-8");
if(request.getParameter("b1")!=null)
session.setAttribute("s4", request.getParameter("b1"));
if(request.getParameter("b2")!=null)
session.setAttribute("s5", request.getParameter("b2"));
if(request.getParameter("b3")!=null)
session.setAttribute("s6", request.getParameter("b3"));
%>
各种球大甩卖,一律八块钱:<br>
<form action="sport.jsp" method="post"></form>
<p><input type="checkbox" name="b1" value="篮球">篮球
<input type="checkbox" name="b2" value="足球">足球
<input type="checkbox" name="b3" value="排球">排球
</p>
<p><input type="submit" name="X1" value="提交">
<a href="meat.jsp">买点别的</a>
<a href="buy.jsp">查看购物车</a>
</p>
</body>
</html>
buy.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>显示购物车购物信息</title>
</head>
<body>
你选择的结果是:<br>
<%request.setCharacterEncoding("UTF-8");
String str="";
if(session.getAttribute("s1")!=null){
str=(String)session.getAttribute("s1");
out.print(str+"<br>");
}
if(session.getAttribute("s2")!=null){
str=(String)session.getAttribute("s2");
out.print(str+"<br>");
}
if(session.getAttribute("s3")!=null){
str=(String)session.getAttribute("s3");
out.print(str+"<br>");
}
if(session.getAttribute("s4")!=null){
str=(String)session.getAttribute("s4");
out.print(str+"<br>");
}
if(session.getAttribute("s5")!=null){
str=(String)session.getAttribute("s5");
out.print(str+"<br>");
}
if(session.getAttribute("s6")!=null){
str=(String)session.getAttribute("s6");
out.print(str+"<br>");
}
%>
</body>
</html>
标签:box import amp 购物车 ssi param 一个 images logs
原文地址:http://www.cnblogs.com/ljs-666/p/7667939.html