📄 shopcartlist.jsp
字号:
<%@ page language="java" import="java.util.*,java.sql.*"
pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>购物车内容</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body,td,th {
font-family: 仿宋_GB2312;
font-size: 18px;
color: #FF0000;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
body {
background-image: url(new/bg-0.jpg);
}
-->
</style></head>
<body>
<%
if(session.getAttribute("username")==null||session.getAttribute("username")=="")
{
response.sendRedirect("relogin.html");//重新登陆
}
%>
<%
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPasswd="ptnest";
String url ="jdbc:mysql://127.0.0.1/bookstore?useUnicode=true&characterEncoding=gb2312" ;
try
{
Class.forName(driverName);
}
catch(ClassNotFoundException e)
{
System.out.print("数据库类没有找到"+e.getMessage());
}
Connection conn= DriverManager.getConnection(url,userName,userPasswd);
Statement stmt=conn.createStatement();
%>
<%
String delename=request.getParameter("bkID");
if(delename!=null)
{
String delsql="delete from orderlist where goodsname='"+delename+"'and user='"+session.getAttribute("username")+"'";
int num=stmt.executeUpdate(delsql);
}
%>
<%
int t=0;
int book;
String sizesql="select * from orderlist where user='"+session.getAttribute("username")+"'";
ResultSet rs=stmt.executeQuery(sizesql);
while(rs.next())
{
t=t+1;
}
if((t%7)>0)
{
book=t/7+1;
}
else
book=t/7;
%>
<%
String pageno,mTmp;
int i,j,k;
pageno=request.getParameter("pageno");
if(pageno==null)
{
pageno="1";
}
j=Integer.parseInt(pageno);
if(j<1)j=1;
if(j>book)j=book;
%>
<%
String sql="select *from orderlist,book where orderlist.goodsname=book.name and orderlist.user='"+session.getAttribute("username")+"'";
ResultSet Rs=stmt.executeQuery(sql);
for(k=0;k<(j-1)*7;k++)
{
Rs.next();
}
i=0;
k=1;
out.println("<div align=center><font size=5 color=red><b>购物清单如下:</b></font></div> ");
out.println("<br>");
out.println("<table width=800 align=center bgcolor=#ffc0cb>");
out.println("<tr>");
out.println("<td width=100><b>书名</b></td>");
out.println("<td width=100><b>出版社</b></td>");
out.println("<td width=100><b>库存</b></td>");
out.println("<td width=100><b>精品</b></td>");
out.println("<td width=100><b>单价</b></td>");
out.println("<td width=100><b>数量</b></td>");
out.println("<td width=100><b>详细资料</b></td>");
out.println("<td width=100><b>操作</b></td>");
out.println("</tr>");
out.println("</table>");
int searchnum=0;
while(Rs.next())
{
i=i+1;
if(i==8)
{
k=0;
break;
}
String goodsname,goodsnumber;
String name,press,content;
int storenum,commend,id,BN;
float price;
id=Rs.getInt("id");
name=new String(Rs.getString("goodsname"));
press=new String(Rs.getString("publish_name"));
storenum=Rs.getInt("storenum");
commend=Rs.getInt("commend");
content=new String(Rs.getString("content"));
price=Rs.getInt("price");
goodsname=new String(Rs.getString("goodsname"));
goodsnumber=new String(Rs.getString("goodsnumber"));
out.println("<table width=800 align=center bgcolor=#98fb98>");
out.println("<tr>");
out.println("<td width=100>"+name+"</td>");
out.println("<td width=100>"+press+"</td>");
if(storenum==1)
{
out.println("<td width=100>有</td>");
}
else
{
out.println("<td width=100>无</td>");
}
if(commend==1)
{
out.println("<td width=100>精品</td>");
}
else
{
out.println("<td width=100>非精品</td>");
}
out.println("<td width=100>"+price+"</td>");
out.println("<td width=100>"+goodsnumber+"</td>");
out.println("<td width=100>");
out.println("<a href=files/imformation.jsp?BN="+id+" target='_blank'>[详情]</a></td>");
out.println("<td width=100>");
out.println("<a href=files/shopcartlist.jsp?bkID="+goodsname+">删除</a></td>");
out.println("</tr>");
out.println("</table>");
searchnum++;
}
i=i-k;
Rs.close();
int bkID,bknum,bksum=0;
String mysql="select *from orderlist ,book where book.name=orderlist.goodsname and user='"+session.getAttribute("username")+"'";
try
{
ResultSet r=stmt.executeQuery(mysql);
while(r.next())
{
bkID=r.getInt("book.price");
bknum=r.getInt("goodsnumber");
bksum=bksum+bkID*bknum;
}
}catch(Exception e)
{
e.toString();
}
%>
<table width=800 border=0 align=center>
<tr>
<td bgcolor="#009900" height="4">
<%
out.println("您一共购买了<b><font color=red>"+t+"</font></b>本书");
out.println("一共需要付<b><font color=red>"+bksum+"</font></b>元");
out.println("<br>");
%>
<%
if(j>=1)
{
%>
<div align=center ><a href="files/list.jsp">继续购物</a><a href=files/buy.jsp> 付款确认</a></div>
</td>
</tr>
</table>
<p align=center><font color=blue><b>结果共<font color=red><%=book %></font>页,</b></font>
<font color=blue><b>现在是第<font color=red><%=j %></font>页</b></font></p>
<p align=center><a href=filse/shopcartlist.jsp?pageno=1>首页</a>
<%
int ii=Integer.parseInt(pageno,10);
if(ii>1)
{
ii=ii-1;
}
String front=Integer.toString(ii);
%>
<a href=files/shopcartlist.jsp?pageno=<%=front %>>上一页</a>
<%
}
if(j<=book)
{
int ii=Integer.parseInt(pageno,10);
if(ii<book)
ii=ii+1;
String nextpage=Integer.toString(ii);
%>
<a href=files/shopcartlist.jsp?pageno=<%=nextpage %>>下一页</a><a href=files/shopcartlist.jsp?pageno=<%=book %>>尾页</a>
<%
}
if(book<j)
j=book;
%>
</p>
</body>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -