📄 serch.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<head>
<title>实验查询列表</title>
<style type="text/css">
<!--
.style2 {font-size: 18px;color: #006699;font-weight: bold;}
.STYLE13 {color:#CC3333;font-size: 16px;font-weight: bold;}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<table width="780" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="23"><form action="serch.jsp" method="post" >
<input type="submit" name="Submit" value="查询">
<input type="text" name="keywords">
<select name="select">
<option selected><span class="STYLE11">实验名称</span></option>
<option><span class="STYLE11">指导教师编号</span></option>
</select>
</form></td>
</tr>
<tr>
<td><%! String aa,cc;%>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL = "";
int PageSize =15 ;
int Page = 1;
int totalPage = 1;
int totalrecord = 0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ce){
out.println(ce.getMessage());
}
request.setCharacterEncoding("gb2312");
String str = request.getParameter("keywords");
String stre=request.getParameter("select");
out.print(stre);
if( str == null)
str = "";
conn=DriverManager.getConnection("jdbc:odbc:libwm");
stmt=conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
//算出总行数
strSQL = "SELECT count(*) as recordcount FROM experiments WHERE "+stre+" LIKE '%"+str+"%' AND 开放状态='1'";
rs = stmt.executeQuery(strSQL);
if (rs.next()) totalrecord = rs.getInt("recordcount");
//输出记录
strSQL="SELECT * FROM experiments WHERE "+stre+" LIKE '%"+str+"%' AND 开放状态='1'";
rs=stmt.executeQuery(strSQL);
if(totalrecord % PageSize ==0)// 如果是当前页码的整数倍
totalPage = totalrecord / PageSize;
else // 如果最后还空余一页
totalPage = (int) Math.floor( totalrecord / PageSize ) + 1;
if(totalPage == 0) totalPage = 1;
if(request.getParameter("Page")==null || request.getParameter("Page").equals(""))
Page = 1;
else
try {
Page = Integer.parseInt(request.getParameter("Page"));
}
catch(java.lang.NumberFormatException e){
// 捕获用户从浏览器地址拦直接输入Page=sdfsdfsdf所造成的异常
Page = 1;
}
if(Page < 1) Page = 1;
if(Page > totalPage) Page = totalPage;
rs.absolute((Page-1) * PageSize + 1);
%>
<tr>
<td height="110"><table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td width="40" height="30" class="STYLE13">实验编号</td>
<td width="288" class="STYLE13">实验名称</td>
<td width="70" class="STYLE13">指导教师编号</td>
<td width="70" class="STYLE13">实验介绍</td>
<td width="70" class="STYLE13">选题</td>
</tr>
<%
for(int iPage=1;iPage<=PageSize; iPage++)
{
String no=rs.getString("实验编号");
String subject_name=rs.getString("实验名称");
String teacher_name=rs.getString("指导教师编号");
String jieshao=rs.getString("实验介绍");
%>
<TR>
<TD><span class="STYLE11"><%=no%></span></TD>
<TD><A HREF='view_expinfo.jsp?id=<%=no%>'><span class="STYLE11"><%=subject_name%></A></TD>
<TD><span class="STYLE11"><%=teacher_name%></span></TD>
<TD><span class="STYLE11"><%=jieshao%></span></TD>
<TD><a href="select_exp.jsp?id=<%=no%>"><span class="STYLE11">选择该题</span></a></TD>
</TR>
<%
if(!rs.next()) break;
}
%>
</table>
<FORM Action="serch.jsp" Method="GET">
<%
if(Page != 1) {
out.print(" <A HREF=serch.jsp?Page=1>第一页</A>");
out.print(" <A HREF=serch.jsp?Page=" + (Page-1) + ">上一页</A>");
}
if(Page != totalPage) {
out.print(" <A HREF=serch.jsp?Page=" + (Page+1) + ">下一页</A>");
out.print(" <A HREF=serch.jsp?Page=" + totalPage + ">最后一页</A>");
}
%>
<span class="STYLE11">输入页数:</span>
<input TYPE="TEXT" Name="Page" SIZE="3">
<span class="STYLE11">页数:<font COLOR="Red"><%=Page%>/<%=totalPage%></font> </span>
</FORM></td></tr>
</table></td>
</tr>
</table>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -