📄 search.jsp
字号:
</ul>
<br><br>
<center><< <a href="javascript:history.go(-1)">返回上一页</a></center>
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
}
else {
if(TYPE_OF_SEARCH.equals("username_search")) {
querycount="select count(*) from posts where author like '%"+SEARCH_STRING+"%'";
query="select db,groupid,title,postat,parentid from posts where author like '%"+SEARCH_STRING+"%'";
if(NAME_SEARCH.equals("topictitle_search")) {
querycount+=" and parentid=0";
query+=" and parentid=0";
searchitem="主题";
}
else if(NAME_SEARCH.equals("post_search")) {
querycount+=" and parentid!=0";
query+=" and parentid!=0";
searchitem="回复";
}
else
searchitem="主题与回复";
}
else if(TYPE_OF_SEARCH.equals("keyword_search")) {
querycount="select count(*) from posts where";
query="select db,groupid,title,postat,parentid from posts where";
if(POST_SEARCH.equals("topictitle_search")) {
querycount+=" title like '%"+SEARCH_STRING+"%' and parentid=0";
query+=" title like '%"+SEARCH_STRING+"%' and parentid=0";
searchitem="标题";
}
else if(POST_SEARCH.equals("post_search")) {
querycount+=" content like '%"+SEARCH_STRING+"%'";
query+=" content like '%"+SEARCH_STRING+"%'";
searchitem="内容";
}
else if(POST_SEARCH.equals("both_search")) {
querycount+=" ((title like '%"+SEARCH_STRING+"%' and parentid=0) or content like '%"+SEARCH_STRING+"%')";
query+=" ((title like '%"+SEARCH_STRING+"%' and parentid=0) or content like '%"+SEARCH_STRING+"%')";
searchitem="标题与内容";
}
}
if(!FORUMS_TO_SEARCH.equals("0")) {
querycount+=" and db="+FORUMS_TO_SEARCH;
query+=" and db="+FORUMS_TO_SEARCH;
}
ForumSearchFactory forumSearchFactory=new ForumSearchFactory();
//分页变量定义
int e=20; //'每页显示的记录数
int totalpage=0; //'页面总数
int pages=1; //'显示的当前页面
int count=0; //'库中数据的总记录数
int from=0,to=0; //'从from篇到to篇
int p=0; //'数据库查询从p开始
//取页数
tempSTR=request.getParameter("pages");
if(tempSTR!=null && !tempSTR.equals(""))
pages=Integer.parseInt(tempSTR);
//分页预备
count=forumSearchFactory.getSearchCount(querycount);
totalpage=((count%e==0)?(count/e):(count/e+1));
if(totalpage==0) totalpage=1;
if(pages>totalpage) pages=totalpage;
else if(pages<1) pages=1;
if(count!=0)
from=(pages-1)*e+1;
if(totalpage==pages)
to=count;
else if(count!=0)
to=from+e-1;
p= (pages-1)*e;
query+=" order by db,parentid,postat desc limit "+p+","+e;
%>
<table cellpadding=0 cellspacing=0 border=0 width=<%=tablewidth%> bgcolor=<%=tablebordercolor%> align=center>
<tr>
<td>
<table cellpadding=8 cellspacing=1 border=0 width=100%>
<tr>
<td bgcolor="<%=miscbacktwo%>" valign=middle colspan=4 align=center>
<font face="宋体" color=<%=fontcolormisc%>>
使用<b><%if(TYPE_OF_SEARCH.equals("username_search")) out.print("作者");else out.print("关键字");%></b>搜索方式,在<b><%=searchitem%></b>中搜索到 <b><%=count%></b> 个相匹配的贴子
</font>
</td>
</tr>
<tr>
<td bgcolor=<%=miscbackone%> valign=middle align=center width=45%>
<font face="宋体" color=<%=fontcolormisc%>><b>主题</b></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle align=center colspan=2>
<font face="宋体" color=<%=fontcolormisc%>><b>发表时间、位置</b></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle align=center width=20%>
<font face="宋体" color=<%=fontcolormisc%>><b>关键字匹配说明</b></font>
</td>
</tr>
<%
ArrayList forumSearchVector=forumSearchFactory.getSearch(query);
for(int i=0;i<forumSearchVector.size();i++) {
ForumSearch forumSearch=(ForumSearch)forumSearchVector.get(i);
forumID=forumSearch.getForumID();
topic=forumSearch.getTopic();
int parentID=forumSearch.getParentID();
searchTitle=forumSearch.getTitle();
postAt=forumSearch.getPostAt();
if(parentID!=0)
searchTitle=forumSearch.getSearchTitle()+"(回复)";
if(forumID!=0)
forumName=(new ForumFactory()).getForumName(forumID);
%>
<tr>
<td bgcolor=<%=miscbackone%> valign=middle>
<font face="宋体" color=<%=fontcolormisc%>><B><a href="topic.jsp?forumID=<%=forumID%>&topic=<%=topic%>"><%=searchTitle%></a></B><br></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle colspan=2>
<font face="宋体" color=<%=fontcolormisc%>>所处论坛: <a href="forum.jsp?forumID=<%=forumID%>"><%=forumName%></a><BR>发表时间: <%=postAt%></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle align=center>
<font face="宋体" color=<%=fontcolormisc%>><%if(TYPE_OF_SEARCH.equals("keyword_search")) out.print("找到关键字");else out.print("主题作者");%>: <B><%=SEARCH_STRING%></B></font>
</td>
</tr>
<%
}
%>
<form name=changepages>
<tr>
<td bgcolor="<%=miscbacktwo%>" valign=middle align=center>
<font color=<%=menufontcolor%>>
共<b><%=totalpage%></b>页
当前第<b><%out.print(from+"-"+to);%></b>个
第<b><%=pages%></b>页
</font>
</td>
<td bgcolor="<%=miscbacktwo%>">
<%
if(totalpage!=1) {
%>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=1><IMG alt=首页 border=0 src=images/first.gif width=11 height=10></A>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=<%=(pages<2)?pages:(pages-1)%>><IMG alt=上一页 border=0 src=images/previous.gif width=11 height=10></A>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=<%=(pages>totalpage-1)?totalpage:(pages+1)%>><IMG alt=下一页 border=0 src=images/next.gif width=11 height=10></A>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=<%=totalpage%>><IMG alt=末页 border=0 src=images/last.gif width=11 height=10></A>
<%
}
%>
</td>
<td bgcolor="<%=miscbacktwo%>">
<%
if(totalpage!=1) {
%>
转到:
<SELECT name=pages size=1 onchange="changePages()">
<%
int pagesFrom=1,pagesTo=totalpage;
if(pages<=5 && totalpage-pages>5)
pagesTo=totalpage>=10?10:totalpage;
else if(pages>5 && totalpage-pages>5) {
pagesFrom=pages-4;
pagesTo=pages+5;
}
else if(pages>5 && totalpage-pages<=5)
pagesFrom=totalpage>=10?totalpage-9:1;
if(pagesFrom!=1)
out.println("<OPTION value='search.jsp?action="+action+"&SEARCH_STRING="+SEARCH_STRING+"&TYPE_OF_SEARCH="+TYPE_OF_SEARCH+"&NAME_SEARCH="+NAME_SEARCH+"&POST_SEARCH="+POST_SEARCH+"&FORUMS_TO_SEARCH="+FORUMS_TO_SEARCH+"&pages="+pagesFrom+"'>--more--</OPTION>");
for(int i=pagesFrom;i<=pagesTo;i++) {
if(i==pages) {
out.println("<OPTION value='search.jsp?action="+action+"&SEARCH_STRING="+SEARCH_STRING+"&TYPE_OF_SEARCH="+TYPE_OF_SEARCH+"&NAME_SEARCH="+NAME_SEARCH+"&POST_SEARCH="+POST_SEARCH+"&FORUMS_TO_SEARCH="+FORUMS_TO_SEARCH+"&pages="+i+"' selected>第"+i+"页</OPTION>");
}
else
out.println("<OPTION value='search.jsp?action="+action+"&SEARCH_STRING="+SEARCH_STRING+"&TYPE_OF_SEARCH="+TYPE_OF_SEARCH+"&NAME_SEARCH="+NAME_SEARCH+"&POST_SEARCH="+POST_SEARCH+"&FORUMS_TO_SEARCH="+FORUMS_TO_SEARCH+"&pages="+i+"'>第"+i+"页</OPTION>");
}
if(pagesTo!=totalpage)
out.println("<OPTION value='search.jsp?action="+action+"&SEARCH_STRING="+SEARCH_STRING+"&TYPE_OF_SEARCH="+TYPE_OF_SEARCH+"&NAME_SEARCH="+NAME_SEARCH+"&POST_SEARCH="+POST_SEARCH+"&FORUMS_TO_SEARCH="+FORUMS_TO_SEARCH+"&pages="+pagesTo+"'>--more--</OPTION>");
%>
</SELECT>
<%
}
%>
</td>
<td bgcolor="<%=miscbacktwo%>" align=center>
<font face="宋体" color=<%=fontcolormisc%>><a href="search.jsp"><b>>> 再 次 搜 索 <<</b></a></font>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
<%
}
}
%>
<%@ include file="include/foot.jsp"%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -