?? searchresult.jsp
字號(hào):
<%--
***************文件名 : searchResult.jsp
***************功能 : 查詢結(jié)果頁(yè)
***************作者 : 馬俊
***************接口參數(shù): searchkey 查詢關(guān)鍵字 condition 查詢條件 顯示頁(yè)碼:String ToPage (第一次進(jìn)入時(shí)為1)
***************實(shí)現(xiàn)過程:
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="page.page"%>
<HTML><HEAD><TITLE>查詢</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=JavaScript type=text/JavaScript>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</SCRIPT>
<SCRIPT src="images/alt.js"></SCRIPT>
<LINK href="images/default.css" type=text/css
rel=stylesheet>
<META content="Microsoft FrontPage 6.0" name=GENERATOR></HEAD>
<BODY background=images/crossbig.gif
onmouseover="window.status='【歡迎你光臨我們的網(wǎng)站】如果您喜歡本站,別忘了把本站介紹給您的好友哦!:)';return true"
leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<SCRIPT language=JavaScript>
<!--
function checkss()
{
if(checkspace(document.searchform.searchkey.value !='請(qǐng)輸入關(guān)鍵字')) {
document.searchform.searchkey.focus();
alert("請(qǐng)輸入查詢關(guān)鍵字!");
return false;
}
if(checkspace(document.searchform.searchkey.value)) {
document.searchform.searchkey.focus();
alert("請(qǐng)輸入查詢關(guān)鍵字!");
return false;
}
document.searchform.submit();
}
function checkspace(checkstr) {
var str = '';
for(i = 0; i < checkstr.length; i++) {
str = str + ' ';
}
return (str == checkstr);
}
//-->
</SCRIPT>
<%
//獲得登錄名,若為空則表示未登錄
String logName=(String) session.getValue("logName");
%>
<TABLE cellSpacing=0 cellPadding=0 width=776 align=center border=0>
<TBODY>
<TR>
<TD width=771 height=14>
<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="770" height="120">
<param name="movie" value="images/headnew.swf">
<param name="quality" value="High">
<embed src="images/headnew.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="770" height="120"></object>
</TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=776 align=center
background="images/INDEX_r2_c1.jpg" border=0>
<TBODY>
<TR>
<TD width=160 height=25>
<SCRIPT language=JavaScript type=text/JavaScript>
today=new Date();
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六");
document.write(
"<font color=#ffffff>"+
today.getYear()+"年"+
(today.getMonth()+1)+"月"+
today.getDate()+"日 "+
d[today.getDay()+1]+
"</font>");
</SCRIPT>
</TD>
<% if(logName==null)
{
%>
<TD width=616><IMG height=10 src="images/b.gif"
width=10 align=absMiddle><FONT color=#333333><font color="#FFFFFF"> </font> <A
class=a1 href="index.jsp" target=_top>
<% }
else
{
%>
<TD width=616><IMG height=10 src="images/b.gif"
width=10 align=absMiddle><FONT color=#333333><font color="#FFFFFF"> </font> <A
class=a1 href="main.jsp" target=_top>
<% }
%>
<font color="#FFFFFF">首 頁(yè)</font></A></FONT><FONT color=#333333><font color="#FFFFFF"> | </font>
<A class=a1 href="userPannel.jsp" target=_top>
<font color="#FFFFFF">個(gè)人信息面板</font></FONT><FONT color=#333333><font color="#FFFFFF"> | </font></FONT></a>
<A class=a1 href="newList.jsp?pubDate=2001/2/4&ToPage=1" target=_top>
<font color="#FFFFFF">新品上架</font></A><FONT color=#FFFFFF> | </FONT>
<A class=a1 href="sortList.jsp?sort=計(jì)算機(jī)硬件&ToPage=1" target=_top>
<font color="#FFFFFF">圖書分類</font></A><FONT color=#FFFFFF> |</FONT>
<A class=a1 href="commendList.jsp?limitNum=10&ToPage=1" target=_top>
<font color="#FFFFFF">精品推薦</font></A><FONT color=#FFFFFF> | </FONT>
<A class=a1 href="topList.jsp?limitNum=10&ToPage=1" target=_top>
<font color="#FFFFFF">排行榜</font></A><FONT color=#FFFFFF> | </FONT>
<a class="a1" target="_top" href="help.jsp">
<font color="#FFFFFF">在線幫助</font></a><FONT color=#FFFFFF>|</FONT>
<FONT color=#ffffff> </FONT>
<% if(logName==null)
{
%>
<FONT color=#FF0000>您還沒有登錄!!!</FONT>
<% }
else
{
%>
<FONT color=#FF0000>當(dāng)前登錄用戶:<%=logName%></FONT>
<%
}
%>
<DIV></DIV></TD></TR></TBODY></TABLE>
<TABLE id=Table1 cellSpacing=0 cellPadding=0 width=776 align=center border=0>
<TBODY>
<TR>
<FORM id=Search name=searchform
action=searchResult.jsp?ToPage=1 method=post>
<TD bgColor=#cce3e7 height=26>
<DIV align=center> </DIV>
<DIV align=center><IMG height=16
src="images/search.gif" width=64 align=absMiddle>
<INPUT onfocus="this.value=''" value=請(qǐng)輸入關(guān)鍵字 name=searchkey size="20">
<SELECT id=action name=condition>
<OPTION value=1 selected>書 名</OPTION>
<OPTION value=2>作 者</OPTION>
<OPTION value=3>出版社</OPTION>
<OPTION value=4>ISBN</OPTION>
</SELECT>
<INPUT id=Submit1 style="BORDER-RIGHT: #333333 1px solid; BACKGROUND-POSITION: 0% 50%; BORDER-TOP: #333333 1px solid; FONT-WEIGHT: normal; FONT-SIZE: 12px; BACKGROUND-ATTACHMENT: scroll; BORDER-LEFT: #333333 1px solid; COLOR: #333333; LINE-HEIGHT: normal; BORDER-BOTTOM: #333333 1px solid; BACKGROUND-REPEAT: repeat; FONT-STYLE: normal; HEIGHT: 18px; BACKGROUND-COLOR: #cee7ef; FONT-VARIANT: normal" onclick="return checkss();" type=submit value=立即查詢 name=Submit>
</DIV></TD></FORM></TR></TBODY></TABLE>
<%
String searchkey=request.getParameter("searchkey"); //查詢關(guān)鍵字
String condition=request.getParameter("condition"); //查詢關(guān)鍵字的值
String strCondition=new String();
int ShowPage=0; //顯示的頁(yè)號(hào)
if(condition.equals("1"))
strCondition="書名";
else if(condition.equals("2"))
strCondition="作者";
else if(condition.equals("3"))
strCondition="出版社";
String sql="SELECT * FROM book WHERE ";
if(strCondition.equals("作者"))
sql=sql+"bookAuthor='";
else if(strCondition.equals("書名"))
sql=sql+"bookName='";
else if(strCondition.equals("出版社"))
sql=sql+"publisher='";
sql=sql+searchkey;
sql=sql+"'";
// out.println(sql);
page myPage=(page)session.getValue("myPage"); //獲得page對(duì)象
if(myPage==null) //第一次進(jìn)入查詢
{
myPage=new page();
myPage.pageSize = 10; //設(shè)置每張網(wǎng)頁(yè)顯示兩筆記錄
myPage.pageID = 1; //設(shè)置欲顯示的頁(yè)數(shù)
myPage.recordCount = 0; //ResultSet的記錄筆數(shù)
myPage.pageCount = 0; //ResultSet分頁(yè)后的總頁(yè)數(shù)
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
out.println(e.toString());
}
try
Connection con = DriverManager.getConnection("jdbc:odbc:bookStore");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery(sql);
rs.last(); //將指標(biāo)移至最后一筆記錄
//取得ResultSet中記錄的筆數(shù)
myPage.recordCount = rs.getRow();
//計(jì)算顯示的頁(yè)數(shù)
myPage.pageCount = ((myPage.recordCount % myPage.pageSize) == 0 ? (myPage.recordCount/myPage.pageSize) : (myPage.recordCount/myPage.pageSize)+1);
if(myPage.recordCount<=0) //沒有找到
{
%>
<p>
<p>
<p>
<img border="0" src="images/5.gif" width="180" height="30"><p>
<p>
<p>
<%
}
else
{
%><CENTER>
<table width="750" border="0" cellspacing="1" cellpadding="1">
<tr valign="top">
<td width="638" align="center">
<td width="638" align="center">
<p> </p><font color="#00FF00"><font size="2"> 該類記錄共有
</font>
<FONT SIZE = 2 COLOR = red>
<%= myPage.pageCount %></FONT><font size="2">頁(yè),您目前在第</font><FONT SIZE = 2 COLOR = red>
<%= ShowPage %></FONT><font size="2">頁(yè)</font></font><font size="2"><b><font color="#0000FF"> </font></b> </font><p>
<b><font color="#0000FF"> </font></b></p>
<p> <img border="0" src="images/8.gif" width="149" height="37"></p>
<center>
<table width="732" border="1" cellspacing="1" cellpadding="1" bordercolor="#FFFFFF">
<tr align="center">
<td width="62" bordercolor="#FFFFFF"> </td>
<td width="142" bordercolor="#0000FF">圖書名稱</td>
<td width="114" bordercolor="#0000FF">作者</td>
<td width="92" bordercolor="#0000FF">圖書類別</td>
<td width="133" bordercolor="#0000FF">出版社</td>
<td width="102" bordercolor="#0000FF">單價(jià)(元)</td>
<td width=175 bordercolor="#0000FF">選擇</td>
<%
//利用For循環(huán)配合myPage.pageSize屬性輸出一頁(yè)中的記錄
for(int i = 1; i <= myPage.pageSize; i++)
{
%>
<tr> <td width="62" align="center" bordercolor="#FFFFFF"> </td>
<td width="142" align="center" bordercolor="#0000FF"><%= rs.getString("bookName") %></td>
<td align="center" width="114" bordercolor="#0000FF"><%=rs.getString("bookAuthor") %></td>
<td align="center" width="92" bordercolor="#0000FF"><%=rs.getString("bookSort") %></td>
<td align="center" width="133" bordercolor="#0000FF"><%=rs.getString("publisher") %></td>
<td align="center" width="102" bordercolor="#0000FF"><%=rs.getString("bookPrice") %></td>
<td align="center" width="175" bordercolor="#0000FF"> <a href="orderView.jsp?bookID=<%=rs.getString("bookID") %>" >購(gòu)買</a>
| <a href="detailView.jsp?bookID=<%=rs.getString("bookID") %>">詳細(xì)資料</a></td>
</tr>
<%
//下面的if判斷語(yǔ)句用于防止輸出最后一頁(yè)記錄時(shí),
//將記錄指標(biāo)移至最后一筆記錄之后
if(!rs.next()) //判斷是否到達(dá)最后一筆記錄
break; //跳出for循環(huán)
}
} //沒有圖書else的結(jié)束
rs.close();
}
catch(Exception e)
{
out.println(e.toString());
}
%>
</table>
</center>
<TABLE width="649">
<TR valign=baseline align=center>
<%
//判斷目前所在分頁(yè)是否為第一頁(yè),
//不是則顯示到第一頁(yè)與上一頁(yè)的超鏈接
//if(ShowPage != 1)
//{
//下面建立的各超鏈接將鏈接至自己,
//并將欲顯示的分頁(yè)以ToPage參數(shù)傳遞給自己
%>
<TD Width=118>
</TD>
<TD Width=89>
<A Href=searchResult.jsp?condition=<%=condition%>&searchkey=<%=searchkey%>&ToPage=<%= 1 %>>到第一頁(yè)</A>
</TD>
<TD Width=95>
<A Href=searchResult.jsp?condition=<%=condition%>&searchkey=<%=searchkey%>&ToPage=<%= ShowPage - 1 %>>到上一頁(yè)</A>
</TD>
<%
//}
//判斷目前所在分頁(yè)是否為最后一頁(yè),
//不是則顯示到最后一頁(yè)與下一頁(yè)的超鏈接
if(ShowPage != myPage.pageCount)
{
//下面建立的各超鏈接將鏈接至自己,
//并將欲顯示的分頁(yè)以ToPage參數(shù)傳遞自己
%>
<TD Width=97>
<A Href=searchResult.jsp?condition=<%=condition%>&searchkey=<%=searchkey%>&ToPage=<%= ShowPage + 1%>>到下一頁(yè)</A>
</TD>
<TD Width=94>
<A Href=searchResult.jsp?condition=<%=condition%>&searchkey=<%=searchkey%>&ToPage=<%= myPage.pageCount %>>到最后一頁(yè)</A>
</TD>
<%
}
%>
<TD Width=118>
<FORM action=searchResult.jsp?condition=<%=condition%>&searchkey=<%=searchkey%> method=POST>
到
<!--
供用戶輸入欲查看頁(yè)數(shù)的文字方塊, 預(yù)設(shè)值為目前所在的分頁(yè),
當(dāng)用戶在此文字方塊中完成數(shù)據(jù)輸入后按下 Enter 即可將數(shù)據(jù)送出,
相當(dāng)于按下Submit按鈕, 因此此表單中將省略Submit按鈕
-->
<INPUT type="text" name=ToPage style="HEIGHT: 25px; WIDTH: 40px"
value=<%= ShowPage%> > 頁(yè)
</FORM></TD></TR>
</TABLE>
</CENTER>
<TABLE cellSpacing=0 cellPadding=0 width=776 align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=1 cellPadding=0 width="100%" align=center
bgColor=#89bec6 border=0>
<TBODY>
<TR bgColor=#aacfd5>
<TD style="PADDING-LEFT: 10px"> </TD>
</TR>
</TBODY></TABLE>
<DIV align=center></DIV></TD></TR>
<TR>
<TD height=6></TD></TR>
</TBODY></TABLE>
<HR align=center width=776 color=#339999 SIZE=1>
<TABLE cellSpacing=0 cellPadding=0 width=776 align=center border=0>
<TBODY>
<TR>
<TD align=middle>版權(quán)所有 2003-2004 © All rights MagicTeam reseverd
<p> </p>
</TD></TR></TBODY></TABLE>
<DIV align=center></DIV>
</table>
</BODY></HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -