📄 cart.jsp
字号:
<%@page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.lang.Math.*" %>
<jsp:useBean id="conn" scope="page" class="myshop.conn"/>
<% request.setCharacterEncoding("gb2312"); %>
<%!
int counter=0;
String shop="";
String price;
String quantity="";
String sql="";
%>
<%
if(request.getParameter("rm")!=null){
session.removeAttribute("shop"+request.getParameter("rm"));
session.removeAttribute("price"+request.getParameter("rm"));
session.removeAttribute("quantity"+request.getParameter("rm"));
}%>
<%
if(request.getParameter("view")==null&request.getParameter("shop")!=null){
if(request.getParameter("shop")!=null&request.getParameter("price")!=null){
shop=request.getParameter("shop");
price=request.getParameter("price");
quantity=request.getParameter("quantity");
session.setAttribute("shop"+counter,shop);
session.setAttribute("price"+counter,price);
session.setAttribute("quantity"+counter,quantity);
counter++;
%>
<jsp:forward page="index.jsp"/>
<%
}else{
out.println("获取信息错误!");
}
}else{%>
<html>
<head>
<title>查看购物车</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body bgcolor="#FFFFCC">
<div align="center"><center>
<FONT size="5pt" face="华文中宋" COLOR="#6699FF"><B>您购买的所有物品如下:</B></FONT>
<table border="0" bgcolor="#D9D98C" bordercolor="#667A7B"
bordercolorlight="#5AAFB4" bordercolordark="#3A4749">
<tr bgcolor="#CCCCFF">
<td align="center"><strong>商品名称</strong></td>
<td align="center"><strong>商品单价</strong></td>
<td align="center"><strong>数量</strong></td>
<td align="center"><strong>操作</strong></td>
</tr>
<%
for(int i=0;i<counter;i++){
if(session.getAttribute("shop"+i)!=null){%>
<tr>
<td align="center"><%=session.getAttribute("shop"+i) %> </td>
<td align="center">¥<%= session.getAttribute("price"+i) %> 元</td>
<td align="center"><%=session.getAttribute("quantity"+i)%></td>
<td><a href=ud.jsp?id=<%=i%>>修改</a> <a href=cart.jsp?rm=<%=i%>>移除</a></td>
</tr><%}else{continue;}%>
<%
}
}
%>
</table><BR><BR>
<A HREF="index.jsp"><FONT SIZE="" COLOR="#99CC00">继续购买</FONT></A>
</center></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -