📄 bookindex.jsp
字号:
<%-- 这个JSP脚本是用来反回图书信息并且处理图书订购的 --%>
<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page errorPage="errorpage.jsp" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="DBexecuteBean" scope="session" class="bookSearchOrderBean.DBexecuteBean"/> <%-- 调用JavaBean --%>
<jsp:useBean id="PageOneByOne" scope="session" class="bookSearchOrderBean.PageOneByOne"/>
<html>
<head>
<title>网上图书信息检索和订购</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.TableLine { border: #6666FF; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
-->
</style>
</head>
<%
String islogin = null;
Cookie[] bookcookie = request.getCookies();
/* 首先验证访问者是否已经登录 */
if(bookcookie != null)
{
for(int j = 0;j < bookcookie.length;j++)
{
if(bookcookie[j].getName().equals("hadlogin"))
{
islogin = bookcookie[j].getValue();
}
}
}
if((islogin == null) || (!(islogin.equals("1"))))
{
throw new Exception("你还没有登录,请先登录!");
}
%>
<body bgcolor="#FFFFFF" link="#009900" vlink="#009900" alink="#009900">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="TableLine">
<tr>
<td height="216">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="2">
<div align="center"><font color="#6666FF" size="5" face="华文新魏"><font size="+3"><b><font size="6">图书目录</font></b></font></font></div>
<%
/* 取得查询的条件 */
String Searchway = null;
String BookName = null;
String AuthorName = null;
String BookType = null;
String PubCompany = null;
String ISBNID = null;
String selectOp = null;
String strPrice;
Double bookPrice;
int totalRecs = -1;
int i = 0;
String urllink = null;
String sSQLCmd1 = null;
String sSQLCmd2 = null;
ResultSet rset = null;
Searchway = request.getParameter("radiobuttonSearch");
BookName = request.getParameter("textfieldTxt_BookName");
AuthorName = request.getParameter("textfieldTxt_AuthorName");
BookType = request.getParameter("selectBookType");
PubCompany = request.getParameter("textfieldTxt_PubCompany");
ISBNID = request.getParameter("textfieldTxt_ISBN");
selectOp = request.getParameter("selectOp");
strPrice = request.getParameter("textfieldTxt_Price");
if(Searchway == null || Searchway.length() < 1)
{
/* 当进行分页显示时,通过sesssion可以读取原始的sql语句 */
Searchway = (String)session.getValue("Searchway");
sSQLCmd1 = (String)session.getValue("sSQLCmd1"); // 从session中取出以前保存的sql语句
sSQLCmd2 = (String)session.getValue("sSQLCmd2");
}
else
{
if(Searchway.equals("0"))
{
/* 浏览所有的图书信息 */
sSQLCmd1 = "Select count(*) from BookList";
sSQLCmd2 = "select ID,BookName,Type,Author,PubCompany,ISBN,Price from booklist";
session.putValue("Searchway",Searchway);
}
else
{
/* 组合查询 */
sSQLCmd1 = "Select count(*) from BookList where BookName is not null ";
sSQLCmd2 = "select ID,BookName,Type,Author,PubCompany,ISBN,Price from booklist where Bookname is not null ";
session.putValue("Searchway",Searchway);
if((BookName != null) && (BookName.length() > 0))
{
BookName = new String(BookName.trim().getBytes("iso-8859-1"));
sSQLCmd1 = sSQLCmd1 + " and BookName = '" + BookName + "' ";
sSQLCmd2 = sSQLCmd2 + " and BookName = '" + BookName + "' ";
}
if((AuthorName != null) && (AuthorName.length() > 0))
{
AuthorName = new String(AuthorName.trim().getBytes("iso-8859-1"));
sSQLCmd1 = sSQLCmd1 + " and Author = '" + AuthorName + "' ";
sSQLCmd2 = sSQLCmd2 + " and Author = '" + AuthorName + "' ";
}
if((BookType != null) && (BookType.length() > 0))
{
BookType = new String(BookType.trim().getBytes("iso-8859-1"));
sSQLCmd1 = sSQLCmd1 + " and Type = '" + BookType + "' ";
sSQLCmd2 = sSQLCmd2 + " and Type = '" + BookType + "' ";
}
if((PubCompany != null) && (PubCompany.length() > 0))
{
PubCompany = new String(PubCompany.trim().getBytes("iso-8859-1"));
sSQLCmd1 = sSQLCmd1 + " and PubCompany = '" + PubCompany + "' ";
sSQLCmd2 = sSQLCmd2 + " and PubCompany = '" + PubCompany + "' ";
}
if((ISBNID != null) && (ISBNID.length() > 0))
{
ISBNID = ISBNID.trim();
sSQLCmd1 = sSQLCmd1 + " and ISBN = '" + ISBNID + "' ";
sSQLCmd2 = sSQLCmd2 + " and ISBN = '" + ISBNID + "' ";
}
if((strPrice != null) && (strPrice.length() > 0) && (selectOp != null) && (selectOp.length() > 0))
{
selectOp = selectOp.trim();
strPrice = strPrice.trim();
try
{bookPrice = new Double(strPrice);}
catch(Exception e)
{throw new Exception("请正确填写图书的价格!");}
sSQLCmd1 = sSQLCmd1 + " and Price " + selectOp + bookPrice;
sSQLCmd2 = sSQLCmd2 + " and Price " + selectOp + bookPrice;
}
}
session.putValue("sSQLCmd1",sSQLCmd1); // 把Sql语句放到session中,以供分页时使用
session.putValue("sSQLCmd2",sSQLCmd2);
}
%>
</td>
</tr>
<tr>
<td height="2"> </td>
</tr>
<tr>
<td height="2">
<div align="right"><b><font face="华文中宋"><font face="华文细黑"><a href="http://127.0.0.1/chapter5/book/OrderList.jsp" target="_blank"><i>查看临时定单
</i></a></font></font></b></div>
</td>
</tr>
<%
/* 调用JavaBean进行数据库操作 */
rset = DBexecuteBean.getTableRecords(sSQLCmd1); //调用Bean中的getTableRecords()方法获得记录结果集的总数
while(rset.next())
{
totalRecs = rset.getInt(1);
}
if(totalRecs < 1)
{
throw new Exception("对不起,没有找到相应的记录!");
}
else
{
rset = PageOneByOne.procPagesAndRecords(totalRecs,sSQLCmd2,request); // 实现分页
urllink = PageOneByOne.cutPage(); // 建立URL连接对象
if(PageOneByOne.TotalPages > 0)
{
i = 0;
while(rset.next())
{
i++;
if(i > ((PageOneByOne.CurrentPage -1) * PageOneByOne.perPageRecs) && (i <= PageOneByOne.CurrentPage * PageOneByOne.perPageRecs))
{
out.println("<tr>");
out.println("<td height=\"48\"> ");
out.println("<form method=\"post\" action=\"http://127.0.0.1/chapter5/book/OrderPro.jsp\">");
out.println("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">");
out.println("<tr>");
out.println("<td colspan=\"4\">");
out.println("<input type=\"hidden\" name=\"hiddenfield_id\" value=\"" + rset.getInt(1) + "\">");
out.println("<font size=\"2\">图书名称:" + rset.getString(2) + "</font>");
out.println("</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td colspan=\"3\"><font size=\"2\">作 者:" + rset.getString(4) + "</font></td>");
out.println("<td width=\"49%\"><font size=\"2\">出 版 社:" + rset.getString(5) + "</font></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td colspan=\"3\"><font size=\"2\">ISBN编号:" + rset.getString(6) + "</font></td>");
out.println("<td width=\"49%\">");
double p = (double)((int)(rset.getDouble(7) * 100) / 100.0);
out.println("<font size=\"2\">价 格:" + p + " 元/本</font>");
out.println("<input type=\"hidden\" name=\"hiddenfield_price\" value=\"" + p + "\">");
out.println("</td></tr>");
out.println("<tr>");
out.println("<td colspan=\"4\">");
out.println("<div align=\"left\"><font size=\"2\">订购数量: ");
out.println("<input type=\"text\" name=\"textfield_count\" size=\"6\" maxlength=\"6\" class=\"TableLine\" value=\"1\"> 本 ");
out.println("<input type=\"submit\" name=\"SubmitOrder\" value=\"订购\" class=\"TableLine\">");
out.println("</font></div>");
out.println("</td>");
out.println("</tr>");
out.println("</table>");
out.println("</form>");
out.println("</td>");
out.println("</tr>");
}
}
}
}
%>
<tr><%=urllink%></tr>
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -