📄 search-resutl.jsp
字号:
<%@ page language="java" import="java.util.*" contentType="text/html; charset=gbk" pageEncoding="gbk"%>
<%@ page import="bean.Goods" %>
<jsp:useBean id="GoodsDao" class="bean.GoodsDao" scope="page"></jsp:useBean>
<jsp:useBean id="pager" class="lp.Page" scope="page"></jsp:useBean>
<%
String sql = null;
String value = request.getParameter("book");
String field = request.getParameter("Str_Search");
System.out.println("value 的值为 : " + value);
System.out.println("field 的值为 : " + field);
if("".equals(value))
{
sql = "select * from goods";
//System.out.println("servlet(value:null) 传入的参数是 : " + sql);
}
else if( "bookname".equals(field)) sql = " select * from goods where bookname like '%" + value + "%'";
else if ("author".equals(field)) sql = " select * from goods where author like '%" + value + "%'";
else if ("isbn".equals(field)) sql = " select * from goods where isbn like '%" + value + "%'";
else if ("publish".equals(field)) sql = " select * from goods where publish like '%" + value + "%'";
// out.print("结果查询语句为 : " + sql);
//从数据库中去出结果集
int currentRecord = 0;
ArrayList<Goods> result =GoodsDao.goodsSelect(sql);
//out.print("查询的结果有 " + result.size() + " 条记录.");
pager.setTotalRecord(result.size());
pager.setTotalPage(result.size(),pager.getPageSize());
//计算并设置分页的参数
if(request.getParameter("currentRecord")!=null)
{
currentRecord = Integer.parseInt(request.getParameter("currentRecord"));
pager.setCurrentRecord(currentRecord);
pager.setCurrentPage(currentRecord,pager.getPageSize());
}
//从结果集中取出当前页面要显示的子集
List<Goods> subResult = null;
if(currentRecord == 0 && result.size() > pager.getPageSize())
{
subResult = result.subList(0,pager.getPageSize());
}
else if(currentRecord == 0 && result.size() < pager.getPageSize())
{
subResult = result.subList(0,result.size());
}
if(pager.getCurrentRecord()+pager.getPageSize()<result.size()
|| pager.getCurrentRecord()+pager.getPageSize()==result.size())
subResult = result.subList(pager.getCurrentRecord(),pager.getCurrentRecord()+pager.getPageSize());
else
subResult = result.subList(pager.getCurrentRecord(),result.size());
%>
<!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=gbk">
<link rel="stylesheet" rev="stylesheet" href="css/style.css" type="text/css" media="all" />
<link href="temp.files/books.css" rel="stylesheet" type="text/css">
<title>search result</title>
<script language="javascript">
//创建XMLHttpReques对象
function createXMLHttpRequest() {
if (window.XMLHttpRequest) {
//Mozilla 浏览器
XMLHttpReq = new XMLHttpRequest();
} else{
// IE浏览器
if (window.ActiveXObject) {
try {
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try {
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e) { }
}
}
}
}
//处理服务器响应结果
function handleResponse()
{
// 判断对象状态
if (XMLHttpReq.readyState == 4)
{
// 信息已经成功返回,开始处理信息
if (XMLHttpReq.status == 200)
{
var out = "";
var failing = "failing";
var logout = "logout";
var res = XMLHttpReq.responseXML;
var response= res.getElementsByTagName("response")[0].firstChild.nodeValue;
// System.out.println("servlet传过来的参数为: " + response); 在这里不能用这样的语句!!
if( logout == response)
{
document.getElementById("display").innerHTML =
"<DIV id = 'display'>" +
"<div id = 'noting'><br>欢迎您从这里登录!</div><br>" +
"<form><div>用户名:<input type = text id = 'name' size = 15></div>" +
"<div id = 'ps'>密 码:<input type = password id = 'pswd' size = 15></div>" +
"<div><input type='button' value='登录' onclick='sayHello()' />" +
"<input type = reset name = 'reset' value = '重置' ></div><br>" +
"<div><A href='' target=_blank>新用户注册</A><A href=''> <FONT color=#ff6600>找回密码</FONT></A></div>" +
"</form>" + "</DIV>"
}
else if( failing == response )
{
document.getElementById("noting").innerHTML = "<br>你的输入有误请重新输入!";
document.getElementById("ps").innerHTML = "密 码:<input type = password id = 'pswd' size = 15>";
}
else if ( null != response )
{
document.getElementById("display").innerHTML =
"<div id = 'display'><div> </div><div><FONT color=blue size=3>" + response + " ,您好!</FONT></div>" +
"<div><br><FONT color=green>三方图书网 </FONT>欢迎您的光临!</div><div><br>谢谢您对我们的支持!</div><br>" +
"<div><input type='button' value='注销登录' onclick='logout()'/></div><br>" +
"<div><A href='http://www.bookschina.com/reguser/default.asp' target=_blank>查看我的帐户</A></div></div>";
}
}
}
}
//发送客户端的请求
function sendRequest(url) {
createXMLHttpRequest();
XMLHttpReq.open("GET", url, true);
//指定响应函数
XMLHttpReq.onreadystatechange = handleResponse;
// 发送请求
XMLHttpReq.send(null);
}
//开始调用Ajax的功能
function sayHello()
{
var name = document.getElementById("name").value;
var pswd = document.getElementById("pswd").value;
// 发送请求
sendRequest("SayHello?name="+name+"&pswd="+pswd);
}
function logout()
{ // 发送请求
sendRequest("SayHello?logout=" + true );
}
</script>
</head>
<body>
<!---top start--->
<div>
<div
style="position: absolute; top: 0px; left: 0px;height: 200px; width: 1000px; border-top: 2px solid blue;
border-bottom: 2px solid blue; border-left:2px solid blue; border-right: 2px solid blue;">
<div style="height: 80px; width: 1000px;">
<div style="float:left; width: 285px;">
<UL style="MARGIN-TOP: 13px; ">
<IMG src="temp.files/logo.gif" border=0>
</UL>
</div>
<div style="float: left;">
<UL style="MARGIN-TOP: 18px">
<FONT color=#cc0000>本站58万种现货图书!特价图书4折封顶!</FONT>
</UL>
<UL style="MARGIN-TOP: 18px">
<A href="frame.htm"><IMG
src="temp.files/index.jpg" align=absBottom> </A>
<A href="frame.htm"><IMG
src="temp.files/book.jpg" align=absBottom> </A>
<A href=frame.htm><IMG
src="temp.files/pifa.jpg" align=absBottom> </A>
</UL>
</div>
<div style="float: left;">
<UL style="MARGIN-TOP: 8px">
<A href="Buy.jsp" alt="购物车"><IMG
id=IMG1 alt=查看您已订购的图书 src="temp.files/shopcar.jpg"
border=0 name=IMG1>
</A>
<br>
<A href="Buy.jsp">购物车</A>
</UL>
</div>
<div style="float: left;">
<UL style="MARGIN-TOP: 8px">
<A href="Regedit.jsp"
target=_blank><IMG alt=注册三方图书网会员,买特价打折书
src="temp.files/shopshow.jpg" border=0>
</A>
<br>
<A href="Regedit.jsp"
target=_blank>注册会员</A>
</UL>
</div>
<div style="float: left;">
<UL style="MARGIN-TOP: 8px">
<A href="my_Account.jsp"><IMG
alt=查看您的个人帐户 src="temp.files/onlinehelp.jpg" border=0>
</A>
<br>
<A href="my_Account.jsp"
target=_blank>我的帐户</A>
</UL>
</div>
<div style="float: left;width:285px;">
<UL style="MARGIN-TOP: 13px">
<A href="frame.htm" target=_blank><IMG
alt=欢迎光临中国图书网 src="temp.files/logo.gif" border=0>
</A>
</UL>
</div>
</div>
<DIV class=br> </DIV>
<div style="absolute; top: 100px;">
<DIV class=guide">
<UL>
<A id=glitter href="Sort.jsp?sort=特价图书">
<FONT size=+0>特价图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=文学图书">
<FONT size=+0>文学图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=生活图书">
<FONT size=+0>生活图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=经管图书">
<FONT size=+0>经管图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=社科图书">
<FONT size=+0>社科图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=艺术图书">
<FONT size=+0>艺术图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=少儿图书">
<FONT size=+0>少儿图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=礼品图书">
<FONT size=+0>礼品图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=新书上架"">
<FONT size=+0>新书上架</FONT></A>|
<A id=glitter href="Sort.jsp?sort=哲学图书"">
<FONT size=+0>哲学图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=农业科学图书">
<FONT size=+0>农业科学图书</FONT></A>
</UL>
<br>
<UL>
<A id=glitter href="Sort.jsp?sort=农业科学">
<FONT size=+0>集团购买</FONT></A>|
<A id=glitter href="Sort.jsp?sort=农业科学">
<FONT size=+0>语言图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=考试图书">
<FONT size=+0>考试图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=教材图书">
<FONT size=+0>教材书店</FONT></A>|
<A id=glitter href="Sort.jsp?sort=计算机技术">
<FONT size=+0>计算机书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=建筑图书">
<FONT size=+0>建筑图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=医学图书">
<FONT size=+0>医学图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=法律图书">
<FONT size=+0>法律图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=外文原版">
<FONT size=+0>外文原版</FONT></A>|
<A id=glitter href="Sort.jsp?sort=音乐图书">
<FONT size=+0>音乐图书</FONT></A>|
<A id=glitter href="Sort.jsp?sort=自然科学数">
<FONT size=+0>自然科学图书</FONT></A>
</UL></DIV>
</div><br>
<div>
<div style="float:left; width: 140px; "> </div>
<DIV class=s1>本站58万种现货图书搜索 请输入关键字:</DIV>
<form action = "search-resutl.jsp" method = "get">
<DIV class=s2>
<%if("" != request.getParameter("book")) {%>
<INPUT id="stp" size=35 onFocus="this.value=''"
value=<%= request.getParameter("book")%> name=book>
<% }else { %>
<INPUT id="stp" size=35 onFocus="this.value=''"
value="关键字1 关键字2 关键字3" name=book>
<% } %>
</DIV>
<DIV class=s2><SELECT id=Select1 name=Str_Search>
<%
if("bookname".equals(request.getParameter("Str_Search"))) {%>
<OPTION value=bookname selected>书名</OPTION>
<OPTION value=author>作者</OPTION>
<OPTION value=publish>出版社</OPTION>
<OPTION value=isbn>ISBN</OPTION>
<%}else if("author".equals(request.getParameter("Str_Search")) ) { %>
<OPTION value=bookname>书名</OPTION>
<OPTION value=author selected>作者</OPTION>
<OPTION value=publish>出版社</OPTION>
<OPTION value=isbn>ISBN</OPTION>
<%}else if("publish".equals(request.getParameter("Str_Search")) ) { %>
<OPTION value=bookname>书名</OPTION>
<OPTION value=author>作者</OPTION>
<OPTION value=publish selected>出版社</OPTION>
<OPTION value=isbn>ISBN</OPTION>
<% }else if("isbn".equals(request.getParameter("Str_Search")) ) { %>
<OPTION value=bookname>书名</OPTION>
<OPTION value=author>作者</OPTION>
<OPTION value=publish>出版社</OPTION>
<OPTION value=isbn selected>ISBN</OPTION>
<% } %>
</SELECT>
</DIV>
<DIV class=s3><INPUT id=go type=submit value="检索"></DIV>
<DIV class=s4><INPUT id=dmethod type=radio CHECKED value=all
name=dmethod>全部图书 <INPUT id=dmethod1 type=radio value=tejia
name=dmethod><SPAN class=red>特价图书</SPAN></DIV>
</form>
</div>
</div>
<!---top end--->
<!---main start--->
<div>
<div
style="position: absolute; top: 203px; left: 0px; height: 1151px; width: 127px; border-top: 2px solid green; border-bottom: 2px solid green; border-left: 2px solid green; border-right: 2px solid green;margin-buttom:50px;">
<!--图书分类-->
<DIV class=left2>
<DIV class=biaoqiana>
图书分类
</DIV>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -