jsp中分页显示(含有模糊查询)

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym08','猛哥 08','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym09','猛哥 09','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym10','猛哥 10','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym11','猛哥 11','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym12','猛哥 12','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym13','猛哥 13','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym14','猛哥 14','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym15','猛哥 15','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym16','猛哥 16','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym17','猛哥 17','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym18','猛哥 18','1') ;
PreparedStatement pstmt = null ;
String sql = null ;
if(keyWord==null)
{
// 如果为空则没有查询,表示查询出全部
sql = "SELECT COUNT(id) from person" ;
}
else
{
sql = "SELECT COUNT(id) from person WHERE userid LIKE ?
}
catch(Exception e)
{}
%>
<%
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String
DBURL
=
"jdbc:oracle:thin:@192.168.1.110:1521:styleerp" ;
String DBUSER = "SYSTEM" ;
{
pstmt.setString(1,"%"+keyWord+"%") ;
pstmt.setString(2,"%"+keyWord+"%") ;
}
rs = pstmt.executeQuery() ;
%>
<script language="javaScript">
function openPage(curpage)
String DBPASSWORD = "ASDqwe123" ;
Connection conn = null ;
%>
<%
try
{
Class.forName(DBDRIVER) ;
conn
=
DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
{
document.spage.cp.value = curpage ;
// alert(cupage) ;
document.spage.submit() ;
}
function selOpenPage()
{
document.spage.cp.value
=
document.spage.selpage.value ;
jsp+oracle 分页(含模糊查询) CREATE SEQUENCE person_sequ ; CREATE TABLE person ( id int not null primary key , -- sequence userid varchar2(32), name varchar2(32), password varchar2(20) ); INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym01','猛哥 01','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym02','猛哥 02','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym03','猛哥 03','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym04','猛哥 04','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym05','猛哥 05','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym06','猛哥 06','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym07','猛哥 07','1') ;
document.spage.submit() ;
}
</script>
<form name="spage" action="<%=jspUrl%>">
输 入 查 询 关 键 字 : <input type="text" name="kw"
value="<%=keyWord==null?"":keyWord%>"> <input type="submit" value="查询">
<input type="button" value=" 下 一 页 " onClick="openPage(<%=currentPage+1%>)" <%=currentPage==pageSize?"disabled":""%>>
<input type="button" value=" 尾 页 " onClick="openPage(<%=pageSize%>)" <%=currentPage==pageSize?"disabled":""%>>
<% if(allRecorders>0) {
%> <br> <br> <input type="button" value=" 首 页 "
onClick="openPage(1)" <%=currentPage==1?"disabled":""%>>
<input type="button" value=" 上 一 页 " onClick="openPage(<%=currentPage-1%>)" <%=currentPage==1?"disabled":""%>>
<% // 进行乱码处理 request.setCharacterEncoding("GB2312") ;
%> <%!
final String jspUrl = "list_person_false_06.jsp" ; %> <%
// 定义如下分页变量 // 1、定义没页要显示的记录数 int lineSize = 10 ; // 2、定义一个当前是第几页 int currentPage = 1 ; // 计算出总页数 int pageSize = 0 ; // 总记录数 / 每页显示的记录数 int allRecorders = 30 ; // 加入查询关键字变量 String keyWord = null ; %> <% // 接收查询关键字
keyWord=new String(request.getParameter("kw").getBytes("8859_1"));
//keyWord = request.getParameter("kw") ;
// 接收传过来的当前页
try
{
currentPage
=
Integer.parseInt(request.getParameter("cp")) ;
OR name LIKE ?" ;
}
pstmt = conn.prepareStatement(sql) ;
// 如果有查询关键字,则进行设置
Βιβλιοθήκη Baidu
if(keyWord!=null)
{
pstmt.setString(1,"%"+keyWord+"%") ;
pstmt.setString(2,"%"+keyWord+"%") ; } ResultSet rs = pstmt.executeQuery() ; if(rs.next()) { allRecorders = rs.getInt(1) ; } rs.close() ; pstmt.close() ; // 计算总页数 pageSize = (allRecorders+lineSize-1)/lineSize ; if(keyWord==null) { sql = "SELECT id,userid,name,password FROM person" ; } else { sql = "SELECT id,userid,name,password FROM person WHERE userid LIKE ? OR name LIKE ?" ; } pstmt = conn.prepareStatement(sql) ; if(keyWord!=null)
INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym19','猛哥 19','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym20','猛哥 20','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym21','猛哥 21','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym22','猛哥 22','1') ; INSERT INTO person(id,userid,name,password) VALUES (person_sequ.nextVal,'ym23','猛哥 23','1') ; list.jsp <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <head> <title>分页显示</title> </head> <body> <center> <h1>人员列表</h1> <hr> <br>
相关文档
最新文档