?? 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 + -