📄 catalog.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="java.util.* " errorPage="" %>
<%@ page import="mypack.*" %>
<%@ include file="common.jsp"%>
<jsp:useBean id="cart" scope="session" class="mypack.ShoppingCart"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>欢迎来到新世纪网上书店</title>
<style type="text/css">
<!--
.style4 {color: #CC6600}
body,td,th {
font-size: 14px;
}
.style5 {color: #CCCCCC}
-->
</style>
</head>
<body>
<p><a href="bookstore.jsp">返回首页</a></p>
<%
// 添加书目
String bookId = request.getParameter("Add");
if (bookId != null) {
BookDetails book = bookDB.getBookDetails(bookId);
cart.add(bookId, book);
%>
<p></p><p class="style4">
您已将 <i><%=book.getTitle()%></i> 加入购物车</p>
</p>
<%
}
if (cart.getNumberOfItems() > 0) {
%>
<p><a href="<%=request.getContextPath()%>/showcart.jsp">查看购物车</a>
<a href="<%=request.getContextPath()%>/cashier.jsp">付账</a></p>
<p>
<%
}
%>
<strong>请选择想购买的书:</strong></p>
<div align="left">
<table align="left">
<tr bgcolor="#999999">
<td >书号</td>
<td >书名</td>
<td >作者</td>
<td >加入购物车</td>
</tr>
<%
String curPageStr = request.getParameter("curPage");
int curPage =1;
int pageSize=4;
if(curPageStr!=null && !"".equals(curPageStr.trim()))
{
curPage = Integer.parseInt(curPageStr);
}
Collection c = bookDB.getBooks(curPage,pageSize);
int totalPage = bookDB.getTotalPage();
Iterator i = c.iterator();
while (i.hasNext()) {
BookDetails book = (BookDetails)i.next();
bookId = book.getBookId();
%>
<tr bgcolor="#00FF33">
<td><%=bookId%></td>
<td><a href="<%=request.getContextPath()%>/bookdetails.jsp?bookId=<%=bookId%>"><strong> <%=book.getTitle()%> </strong></a></td>
<td> <em><%=book.getName()%> </em></td>
<td><a href="<%=request.getContextPath()%>/catalog.jsp?Add=<%=bookId%>"> 加入购物车 </a></td>
</tr>
<% } %>
<tr>
<td><div align="center"><% if(curPage>1) {%><a href="?curPage=<%=(curPage > 1)? curPage -1 :1 %>"> 上一页</a><% }else{ %>
<span class="style5">上一页</span>
<% } %></div></td>
<td><div align="center"><% if(curPage<totalPage) {%><a href="?curPage=<%=(curPage>=totalPage )? totalPage : curPage + 1 %>">下一页</a><% }else{ %>
<span class="style5">下一页</span>
<% } %></div></td>
</tr>
</table>
</div>
<p align="left"> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="left"> </p>
<p align="left">结果共<%=totalPage%>页,显示第<%=curPage%>页
</p>
<%@ include file="bottom.jsp"%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -