jsp session购物车如何实现计算总价和修改数量 50
下面是我的一些关键代码<%String[]titles={"GALAXYNOTE3","IPhone5S","Mui2"};<td><divalign="center">...
下面是我的一些关键代码
<% String[] titles = {"GALAXYNOTE3","IPhone5S","Mui2"};
<td><div align="center"><A HREF=shopping.jsp?itemName=<%=titles[0]%>>加入购物车</A></div>
...titles[1]....titles[2]
//以上是购物车的内容和三个加入购物车按钮
<A HREF=shopping.jsp?itemName=emptyCart>清空购物车</A></TD>
<TD><a href="pay.jsp">支付</a></TD></TR>
</TABLE>
<% String item = request.getParameter("itemName");
if(item != null && item.equals("emptyCart")){
Enumeration attributeNames = session.getAttributeNames();
while(attributeNames.hasMoreElements()){
String attributeName = (String)attributeNames.nextElement();
session.removeAttribute(attributeName);
}
} else if(item != null){
int m=0;
for(int i=0;i<3;i++){
if(item.equals("delete"+titles[i]))
{String attributeName = titles[i];
session.removeAttribute(attributeName);m=1;}
}
if(m==0){String attributeName = item;
session.setAttribute(attributeName,item);}
%>
<HR>
<H1 align="center"> 购物车 </H1>
<UL>
<% Enumeration attributeNames = session.getAttributeNames();
int k=0;
while(attributeNames.hasMoreElements())
{
String attributeName = (String)attributeNames.nextElement();
String attributeValue = (String)session.getAttribute(attributeName);
k++;
%>
<LI><%=attributeValue%> <A HREF=shopping.jsp?itemName=<%="delete"+attributeValue%>>删除</A>
<% } %>
<h3 align="center"><font color="red">您的购物车现有 <%=k%> 件商品! </font></h3>
</BODY>
如何实现在购买的时候可以选择数量,然后在购物车中显示总价呢! 展开
<% String[] titles = {"GALAXYNOTE3","IPhone5S","Mui2"};
<td><div align="center"><A HREF=shopping.jsp?itemName=<%=titles[0]%>>加入购物车</A></div>
...titles[1]....titles[2]
//以上是购物车的内容和三个加入购物车按钮
<A HREF=shopping.jsp?itemName=emptyCart>清空购物车</A></TD>
<TD><a href="pay.jsp">支付</a></TD></TR>
</TABLE>
<% String item = request.getParameter("itemName");
if(item != null && item.equals("emptyCart")){
Enumeration attributeNames = session.getAttributeNames();
while(attributeNames.hasMoreElements()){
String attributeName = (String)attributeNames.nextElement();
session.removeAttribute(attributeName);
}
} else if(item != null){
int m=0;
for(int i=0;i<3;i++){
if(item.equals("delete"+titles[i]))
{String attributeName = titles[i];
session.removeAttribute(attributeName);m=1;}
}
if(m==0){String attributeName = item;
session.setAttribute(attributeName,item);}
%>
<HR>
<H1 align="center"> 购物车 </H1>
<UL>
<% Enumeration attributeNames = session.getAttributeNames();
int k=0;
while(attributeNames.hasMoreElements())
{
String attributeName = (String)attributeNames.nextElement();
String attributeValue = (String)session.getAttribute(attributeName);
k++;
%>
<LI><%=attributeValue%> <A HREF=shopping.jsp?itemName=<%="delete"+attributeValue%>>删除</A>
<% } %>
<h3 align="center"><font color="red">您的购物车现有 <%=k%> 件商品! </font></h3>
</BODY>
如何实现在购买的时候可以选择数量,然后在购物车中显示总价呢! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询