请教一题关于jsp的session问题
老师布置的一道关于session的简易购物车 问题可能出现在了display.jsp中了 每次购物车的显示都是null null 还请好心人指点一下Buy1.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<form method="post"action="display.jsp"><h2>各种肉大甩卖,一律十块:</h2>
<br><input type="checkbox"name="item"value="猪肉">猪肉
<br><input type="checkbox"name="item"value="牛肉">牛肉
<br><input type="checkbox"name="item"value="羊肉">羊肉
<br><input type="submit"value="提交">
<input type="reset"value="全部重写">
</form>
<p><a href="buy2.jsp">买点别的</a>
<a href="display.jsp">查看购物车</a>
</p>
<% String meat[]=request.getParameterValues("item");
if(meat!=null)
{
StringBuffer str=new StringBuffer();
for(int i=0;i<meat.length;i++)
{
str.append(meat[i]+"<br>");
}
session.setAttribute("meat", str);
}
%>
</body>
</html>
Buy2.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<form method="post"action="display.jsp"><h2>各种球大甩卖,一律八块:</h2>
<br><input type="checkbox"name="item1"value="篮球">篮球
<br><input type="checkbox"name="item1"value="足球">足球
<br><input type="checkbox"name="item1"value="排球">排球
<br><input type="submit"value="提交">
<input type="reset"value="全部重写">
</form>
<p><a href="buy1.jsp">买点别的</a>
<a href="display.jsp">查看购物车</a>
</p>
<% String ball[]=request.getParameterValues("item1");
if(ball!=null)
{
StringBuffer str1=new StringBuffer();
for(int i=0;i<ball.length;i++)
{
str1.append(ball[i]+"<br>");
}
session.setAttribute("ball", str1);
}
%>
</body>
</html>
Display.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%! public String handleStr(String s)
{
try
{
byte []b=s.getBytes("iso-8859-1");
s= new String(b);
}
catch(Exception exp){}
return s;
}
%>
<html>
<body>
<% StringBuffer buyMeat=(StringBuffer)session.getAttribute("meat");
StringBuffer buyBall=(StringBuffer)session.getAttribute("ball");
%>
<%
String buyMeat1=(String)session.getAttribute("buyMeat");
String buyBall1=(String)session.getAttribute("buyBall");
out.print("你选择的结果是:"+"<br>");
%>
<%= handleStr(buyMeat1) %>
<%= handleStr(buyBall1) %>
</body>
</html>