请问各位谁有jsp session 购物车代码 请问各位谁有jsp session 购物车代码 ,可以发给我不了,。谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /*Copyright by suoxin in 2003 to example in j2eeHhShop 购物车*/package database;public class ShopCar implements Comparable{ private String name = null ; private float price = 0.0F ; private int number = 0 ; public ShopCar (String name,float price,int number) { this.name = name; this.price = price; this.number = number; } public String getName() { return this.name; } public float getPrice() { return this.price; } public int getNumber() { return this.number; } /* @you must write this method ,to become implement comparable **/ public int compareTo(Object o) { ShopCar n = (ShopCar )o; int lastCam = name.compareTo(n.name); return lastCam; }}在测试中,为了大家理解就用提交的方式购物Car.jsp 复制内容到剪贴板 代码:<%@ page contentType="text/html;charset=gb2312"%><%@ page import="database.ShopCar"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>添加大类</title></head><body><%//判断是否提交String action = request.getParameter("action");if(action == null || action.equals("")){%><form name="myform" method="post" action="url.jsp?action=add"> <table width="600" border="1" align="center"> <tr align="center"> <td colspan="2">添加商品大类</td> </tr> <tr> <td width="121">大类名称:</td> <td width="463"><input type="text" name="name"></td> </tr> <tr> <td width="121">单价:</td> <td><input type="text" name="price"></td> </tr> <tr> <td width="121">数量</td> <td><input type="text" name="number"></td> </tr> <tr align="center"> <td height="17" colspan="2"><input type="submit" name="Submit" value="提交"></td> </tr> </table></form><%}else{String name = request.getParameter("name").trim();String getPrice = request.getParameter("price").trim();float price = Float.parseFloat(getPrice);int number = Integer.parseInt(request.getParameter("number").trim());ShopCar shop = new ShopCar(name,price,number);//建立一个购物对象java.util.ArrayList car = null;java.lang.Object object = session.getAttribute("car");if(object != null){car = (java.util.ArrayList)object;}else{car = new java.util.ArrayList();}car.add(shop);//把购物加到ArrayList对象中session.setAttribute("car",car);//存贮到sessionsession.setMaxInactiveInterval(1800);out.println("提交成功,<a href='Car.jsp'>返回</a>继续");out.println("提交成功,<a href='showCar.jsp'>察看</a>继续");}%></body></html> jsp:forward到struts2的action 急, window player问题 关于java操作telnet协议 httpclient错误,很郁闷,高手100分赐教 如何使用列表框上的value传递信息给其它页(列表中的value信息是数学库中的,使用的是<%=request.getParamer(..)%>形式,请指教 Build path entry is missing: frameworkv2.00.006 请问有否知道struts中html标签如何支持img图片 求助大神,急急急!!!!! 如何修改referrer 怎么做BBS? spring问题。麻烦大家
Copyright by suoxin in 2003 to example in j2ee
HhShop 购物车*/
package database;
public class ShopCar implements Comparable
{
private String name = null ;
private float price = 0.0F ;
private int number = 0 ;
public ShopCar (String name,float price,int number)
{
this.name = name;
this.price = price;
this.number = number;
}
public String getName()
{
return this.name;
}
public float getPrice()
{
return this.price;
}
public int getNumber()
{
return this.number;
}
/*
@you must write this method ,to become implement comparable
**/
public int compareTo(Object o)
{
ShopCar n = (ShopCar )o;
int lastCam = name.compareTo(n.name);
return lastCam;
}
}
在测试中,为了大家理解就用提交的方式购物
Car.jsp
复制内容到剪贴板
代码:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="database.ShopCar"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>添加大类</title>
</head>
<body>
<%
//判断是否提交
String action = request.getParameter("action");
if(action == null || action.equals("")){
%>
<form name="myform" method="post" action="url.jsp?action=add">
<table width="600" border="1" align="center">
<tr align="center">
<td colspan="2">添加商品大类</td>
</tr>
<tr>
<td width="121">大类名称:</td>
<td width="463"><input type="text" name="name"></td>
</tr>
<tr>
<td width="121">单价:</td>
<td><input type="text" name="price"></td>
</tr>
<tr>
<td width="121">数量</td>
<td><input type="text" name="number"></td>
</tr>
<tr align="center">
<td height="17" colspan="2"><input type="submit" name="Submit" value="提交"></td>
</tr>
</table>
</form>
<%
}else{
String name = request.getParameter("name").trim();
String getPrice = request.getParameter("price").trim();
float price = Float.parseFloat(getPrice);
int number = Integer.parseInt(request.getParameter("number").trim());
ShopCar shop = new ShopCar(name,price,number);
//建立一个购物对象
java.util.ArrayList car = null;
java.lang.Object object = session.getAttribute("car");
if(object != null){
car = (java.util.ArrayList)object;
}else{
car = new java.util.ArrayList();
}
car.add(shop);//把购物加到ArrayList对象中
session.setAttribute("car",car);//存贮到session
session.setMaxInactiveInterval(1800);
out.println("提交成功,<a href='Car.jsp'>返回</a>继续");
out.println("提交成功,<a href='showCar.jsp'>察看</a>继续");
}
%>
</body>
</html>