📄 search.jsp
字号:
<%@ page contentType="text/html;charset=gb2312" import="java.sql.*"%>
<%@ include file="top.htm"%>
<jsp:useBean id="conn" class="dbBean.DBBean" scope="session"/>
<jsp:useBean id="sp" class="spage.ShowPage"/>
<html>
<head>
<title>软件搜索</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<%!
String type="全部";
String key="";
String sql1="";
String sql2="";
ResultSet rs=null;
ResultSet temp=null;
//每页显示的记录个数
int size = 10;
//当前页号
int p = 1;
//全部的页数
int totalPage = 1;
%>
<%
request.setCharacterEncoding("gb2312");
if(request.getParameter("stype")!=null)
type=request.getParameter("stype");
if(request.getParameter("skey")!=null)
key=request.getParameter("skey");
%>
<p>
<center>
<form action="search.jsp" method="post">
请选择软件种类:<select name="stype">
<option value="全部" <%if(type!=null) if(type.equals("全部")) out.print("selected");%>>全部</option>
<option value="编程软件" <%if(type!=null) if(type.equals("编程软件")) out.print("selected");%>>编程软件</option>
<option value="病毒软件" <%if(type!=null) if(type.equals("病毒软件")) out.print("selected");%>>病毒软件</option>
<option value="播放软件" <%if(type!=null) if(type.equals("播放软件")) out.print("selected");%>>播放软件</option>
<option value="压缩软件" <%if(type!=null) if(type.equals("压缩软件")) out.print("selected");%>>压缩软件</option>
<option value="网络通讯软件" <%if(type!=null) if(type.equals("网络通讯软件")) out.print("selected");%>>网络通讯软件</option>
<option value="文字处理软件" <%if(type!=null) if(type.equals("文字处理软件")) out.print("selected");%>>文字处理软件</option>
<option value="其他" <%if(type!=null) if(type.equals("其他")) out.print("selected");%>>其他</option>
</select>
请输入查询关键字:<input type="text" name="skey" size=10>
<input type="submit" value="确定">
</form>
<table width="95%">
<tr align="center">
<th background="images/bg1.gif">类型</th><th background="images/bg1.gif">名称</th><th background="images/bg1.gif">推荐指数</th><th background="images/bg1.gif">下载次数</th><th background="images/bg1.gif">加入时间</th>
<%
sql1="select * from sinfo";
sql2="select count(*) from sinfo";
if(type!=null && key!=null)
{
if(!type.equals("全部"))
{
sql1 += " where type ='"+type+"'";
sql2 += " where type ='"+type+"'";
if(!key.equals(""))
{
sql1 += " and name like '%"+key+"%'";
sql2 += " and name like '%"+key+"%'";
}
}
else
{
if(!key.equals(""))
{
sql1 += " where name like '%"+key+"%'";
sql2 += " where name like '%"+key+"%'";
}
}
}
sql1+=" order by times desc";
temp=conn.executeQuery(sql2);
int totalrecord=0;
if(temp.next())
totalrecord = temp.getInt(1);
// 如果是当前页码的整数倍
if(totalrecord % size ==0) totalPage = totalrecord / size;
// 如果最后还空余一页
else totalPage = totalrecord / size + 1;
if(totalPage == 0) totalPage = 1;
temp.close();
try {
if(request.getParameter("p")==null|| request.getParameter("p").equals(""))
{
if(session.getAttribute("seap")==null)
p = 1;
else
p = ((Integer)session.getAttribute("seap")).intValue();
}
else
{
p = Integer.parseInt(request.getParameter("p")); session.setAttribute("seap",new Integer(p));
}
}
// 捕获用户从浏览器地址拦直接输入非数字信息而引起的异常
catch(NumberFormatException e) {
p = 1;
}
if(p < 1) p = 1;
if(p > totalPage) p = totalPage;
rs=conn.executeQuery(sql1);
if(rs.next())
out.println(sp.printPage(rs,p,size,false));
%>
</table>
<form Action="search.jsp" Method="GET">
<%
for(int i=1;i<=totalPage;i++) {
out.println("<a href=search.jsp?p=" + i +">" + i + "</a> ");
}
%>
<p>输入页数:<input type="text" name="p" size="3">
页数:<font color="red"><%=p%>/<%=totalPage%></font>
</p>
</form>
</center>
<%
rs.close();
conn.close();
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -