求分页了啊,有知道的就救救我吧,绝对高分,如果解决了还可以继续加分的,主要是能帮我解决下额
我的问题是:我在Servlet里的DoGet()方法里通过查询数据库,取到相关的值,这些都没问题的,现在我在JSP页面上做了个文本框和个搜索按钮,假如我现在输入个条件的话可以搜索
出来值 我把这些值放在一个表里显示的,我就想在这分页,之前怎么查询啊别管的,我就是想问我不是查询的值以表的形式显示的吗,我要以10条为一页,这该怎么分页啊?求大哥们帮帮忙啊,解决了还可以加分的,谢谢啊!!!拜托了,希望能贴详细和全的 5555555555555555555555555555555555555555555 先发50分 可以加的
做我那样的分页不需要在JAVA类里面写吧,在JSP里不行吗,还有就是象有多少页啊 当前第几页啊是好显示的 就是如果我点上一页或下一页的时候他就会跳页了...应该不跳另一个页面才对吧 应该还是在那地方显示的 这怎么弄的啊???继续求解
我的问题是:我在Servlet里的DoGet()方法里通过查询数据库,取到相关的值,这些都没问题的,现在我在JSP页面上做了个文本框和个搜索按钮,假如我现在输入个条件的话可以搜索
出来值 我把这些值放在一个表里显示的,我就想在这分页,之前怎么查询啊别管的,我就是想问我不是查询的值以表的形式显示的吗,我要以10条为一页,这该怎么分页啊?求大哥们帮帮忙啊,解决了还可以加分的,谢谢啊!!!拜托了,希望能贴详细和全的 5555555555555555555555555555555555555555555 先发50分 可以加的
做我那样的分页不需要在JAVA类里面写吧,在JSP里不行吗,还有就是象有多少页啊 当前第几页啊是好显示的 就是如果我点上一页或下一页的时候他就会跳页了...应该不跳另一个页面才对吧 应该还是在那地方显示的 这怎么弄的啊???继续求解
解决方案 »
- myEclipse中新建了一个jsp文件,但是在浏览器中无法预览,用自带的浏览器也不行,能够打开index.jsp
- 编码问题
- 初用ECLIPSE遇到问题
- 求jxl文档 怎么把jsp中页面表格的是数据写到excel中去
- Struts中利用Action作消息提示的问题?
- no svnjavahl in java.library.path
- 大家如何处理服务器根目录问题,地址存在session,配置文件,还是自己创立的文件中?
- 我的专家分已经490,再多11分,九可以穿三▲了。散分!
- 大家好,送分啦!!!!快来啊!
- 抛出一个“no suitable driver”异常?为什么???
- struts2框架验证问题!
- 程序员必玩的一款小游戏
document.form1.formAction.value="search";
document.form1.currentPageNum.value="1";
document.form1.submit();
}
function onPrepage(){
document.form1.formAction.value="search";
var i=parseInt(document.form1.currentPageNum.value);
if (i>1){
i=i-1;
}
document.form1.currentPageNum.value=String(i);
document.form1.submit();
}
function onNextpage(){
document.form1.formAction.value="search";
var i=parseInt(document.form1.currentPageNum.value);
i=i+1;
document.form1.currentPageNum.value=String(i);
document.form1.submit();
}
function onLastpage(){
document.form1.formAction.value="searchVeh";
document.form1.currentPageNum.value=document.form1.maxPageNum.value;
document.form1.submit();
}function onPage(){
if(document.form1.pageNum.value == "")
{
window.alert("页数不能为空!");
return;
}
if(!isNumber(document.form1.pageNum.value, false))
{
window.alert("页数必需为数字!");
return;
}
var i = parseInt(document.form1.pageNum.value);
var max = parseInt(document.form1.maxPageNum.value);
if(i < 1 | i > max) {
window.alert("页数必许从1到" + max + "!");
return;
}
document.form1.formAction.value = "searchVeh";
document.form1.currentPageNum.value = document.form1.pageNum.value;
document.form1.submit();
}基本就这个思路,需要取得多少页数,得出有几页数。
然后上一页和下一页判断好 第一页和尾页的情况基本就差不多了。
<form action="/PP003/QueryInfoServlet" method="get" name="queryInfo">
<table width="680" border="0" align="center" cellpadding="0" cellspacing="0" class="fonts">
<tr>
<td><input type="text" name="id" style="width:304; font-family: Arial; font-size: 12px; color: #999999; border: 1px solid #cccccc; background-color: #F7F7F7"></td>
<td><input type="button" value="搜索" width="71" height="23" align="center" style="cursor:hand; padding-top: 2px" background="images/an01.jpg" onclick="queryInfo.submit();"></td>
</tr>
</table>
</form>
上面是文本框和一个搜索按狃,就是查询出来的值是这样显示的:
<table id="oTable" width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="9BB8E0" class="fonts">
<tr align="center" bgcolor="#ECF9FF">
<td width="40" height="30" valign="middle">选择</td>
<td width="50" height="30" valign="middle">ID</td>
<td width="50" height="30" align='center'>对象ID</td>
<td width="50" height="30" valign="center">显示描述</td>
<!-- <td width="60" height="30" valign="center">要素属性</td>
<td width="60" height="30" valign="center">名称</td>-->
</tr>
<logic:iterate id="sResult" name="searchResult">
<tr align="center" bgcolor="#FFFFFF" style="cursor:hand;" onmousemove="this.style.background='#ECF9FF'" onmouseout="this.style.background='#FFFFFF'" ondblclick="openXxInfo('${sResult.id }')">
<td height="20"><input type="checkbox" name="cellId" value="checkbox"></td>
<td height="20">${ sResult.id }</td>
<td height="20">${ sResult.dxid }</td>
<td height="20">${ sResult.xsms }</td>
</tr>
</logic:iterate>
</table>该怎么进行分页的啊.....
int count=0,lastp=0,numf,numl,prep=0,nextp=0,pageno;
if(request.getParameter("pageno")==null) //pageno:代表页码
{pageno=0;}
else
pageno=Integer.parseInt(request.getParameter("pageno"));
String path = config.getServletContext().getRealPath("/");
String kind=user.getName();
//System.out.println(kind);
String url = "jdbc:.........";//你数据库的路径
Connection con =null;
Statement smt = null;
ResultSet rs = null;
try{
con = getConnection(url);//你自己改下,目的就是得到Connection实例
String sql="select * from table ";
smt = con.createStatement();
rs = smt.executeQuery(sql);
while(rs.next())
{ count++; }
//count:多少留言
lastp=(int)Math.ceil((double)count/5);
//用来计算此表中有几页留言:ceil返回大于等于其数字参数的最小整数。 //必选项number 参数是数值表达式。//返回值为大于等于其数字参数的最小整数。
if(pageno==0||pageno>lastp)
pageno=lastp;
numf=pageno*5-4; //显示留言的第一笔数据的编号id
numl=numf+4;//numl:此页的最后的一笔数据编号id
if(pageno==1)
prep=1; //prep:上一页
prep=pageno-1;
if(pageno==lastp)
nextp=lastp;
else
nextp=pageno+1;
sql="select * from message LIMIT "+(numf-1)+","+5;
rs=smt.executeQuery(sql);
%>
<form action=你自己的.jsp method=POST>
<table boder=0>
<tr>
<td>目前的页次<font color=red><%=pageno%></font>/<font color=blue><%=lastp%></font></td>
<td><a href=你自己的.jsp?pageno=<%=prep%>&kind=<%=kind%>>[上一页]</a></td>
<%--将参数pageno传递给程序,依据它来计算numl和numf,再将留言数据通过sql取出--%>
<td><a href=board.jsp?pageno=<%=nextp%>>[下一页]</a></td>
<td><a href=board.jsp?pageno=1>[第一页]</a></td>
<td><a href=board.jsp>>[最后一页]</a></td>
<td>输入页次<input type=text size=3 name=pageno></td>
<td><input type=submit name=SEND value=跳转></td>
</tr>
</table>
</form>
int count=0,lastp=0,numf,numl,prep=0,nextp=0,pageno;
if(request.getParameter("pageno")==null) //pageno:代表页码
{pageno=0;}
else
pageno=Integer.parseInt(request.getParameter("pageno"));
String path = config.getServletContext().getRealPath("/");
String url = "jdbc:.........";//你数据库的路径
Connection con =null;
Statement smt = null;
ResultSet rs = null;
try{
con = getConnection(url);//你自己改下,目的就是得到Connection实例
String sql="select * from table ";
smt = con.createStatement();
rs = smt.executeQuery(sql);
while(rs.next())
{ count++; }
//count:多少数据
lastp=(int)Math.ceil((double)count/5);
//用来计算此表中有几页:ceil返回大于等于其数字参数的最小整数。 //必选项number 参数是数值表达式。 //返回值为大于等于其数字参数的最小整数。
if(pageno==0||pageno>lastp)
pageno=lastp;
numf=pageno*5-4; //显示第一笔数据的编号id
numl=numf+4;//numl:此页的最后的一笔数据编号id
if(pageno==1)
prep=1; //prep:上一页
prep=pageno-1;
if(pageno==lastp)
nextp=lastp;
else
nextp=pageno+1;
sql="select * from table LIMIT "+(numf-1)+","+5;
rs=smt.executeQuery(sql);
%>
<form action=你自己的.jsp method=POST>
<table boder=0>
<tr>
<td>目前的页次 <font color=red> <%=pageno%> </font>/ <font color=blue> <%=lastp%> </font> </td>
<td> <a href=你自己的.jsp?pageno= <%=prep%>>[上一页] </a> </td>
<%--将参数pageno传递给程序,依据它来计算numl和numf,再将留言数据通过sql取出--%>
<td> <a href=你自己的.jsp?pageno= <%=nextp%>>[下一页] </a> </td>
<td> <a href=你自己的.jsp?pageno=1>[第一页] </a> </td>
<td> <a href=你自己的.jsp>[最后一页] </a> </td>
<td>输入页次 <input type=text size=3 name=pageno> </td>
<td> <input type=submit name=SEND value=跳转> </td>
</tr>
</table>
</form>
lastp=(int)Math.ceil((double)count/10); 把numf=pageno*5-4; 改为numf=pageno*10-9;
numl=numf+4改为numl=numf+9
sql="select * from table LIMIT "+(numf-1)+","+5;改为sql="select * from table LIMIT "+(numf-1)+","+10;
select * from emp--分页
--三个参数:num每行显示记录数,ys查看第几页,c总行数
create or replace procedure p_fy(num number,ys number,c number)
is
counts number:=c; --总记录数
zys number:=floor(counts/num)+1; --总页数
cursor cur is select * from
(
select emp.*,rownum r from emp
)where r>=((ys*zys)-(num-1)) and r<=ys*zys;
myExcep exception;
begin
if(ys<=0 or ys>zys) then
raise myExcep;
end if;
for item in cur loop
dbms_output.put_line(item.ename);
end loop;
dbms_output.put_line('---第'||ys||'页---'||'共'||zys||'页---'||'每页'||num||'条记录---');
exception
when myExcep then
dbms_output.put_line('该页不存在!');
end;
--调用
declare
c number; --总记录数
rn number:=&每页显示的行数;--每页的行数
ys number:=&查看第几页; --查看第几页
begin
select count(*) into c from emp;
scott.p_fy(rn,ys,c);
end;
int dipage=1;//当前页码数默认为1
String pages=request.getParameter("dipage");
if(pages==null)
{
pages="1";
}
try
{
dipage=Integer.parseInt(pages);
}
catch(Exception e)
{
dipage=1;
}
%>
<%Connection con;
Statement stm;
ResultSet rs;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e)
{
out.print("类找不到!");
}
try{ con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=cspc4java","sa","sa"); stm=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sq="select * from zhaopin order by publishtime desc";
rs=stm.executeQuery(sq);
int countRecord=0;//记录条数
int countPageRecord=0;//每页记录条数
int countPage=1;//总页数
countPageRecord=20;//每页5条记录,要设置每页记录条数就更改这个变量的值
rs.last();
countRecord=rs.getRow();
if(countRecord/countPageRecord==0)
countPage=countRecord/countPageRecord;
else
countPage=countRecord/countPageRecord+1;
if((dipage-1)*countPageRecord==0)
rs.beforeFirst();
else
rs.absolute((dipage-1)*countPageRecord);
%>
<%
int i=0;
while(rs.next())
{i++;
String id=rs.getString("id");
String name=rs.getString("name");
String publishtime=rs.getString("publishtime").substring(0,10);
String endtime=rs.getString("endtime").substring(0,10);
String department=rs.getString("department");
String workplace=rs.getString("workplace");
String gongzuoxingzhi=rs.getString("gongzuoxingzhi");
%>
<tr onmouseover=this.bgColor='#e7efd6' onmouseout=this.bgColor='white'>
<td><input name="zhaopin" type="checkbox" value="<%=name %>" /></td>
<td><a href="<%=request.getContextPath() %>/jobInfoDetail.jsp?id=<%=id %>&name=<%=name %>"><%=name %></a></td>
<td><%=department %></td>
<td><%=gongzuoxingzhi %></td>
<td><%=workplace %></td>
<td><%=publishtime %></td>
<td><%=endtime %></td> </tr>
<%if(i>=countPageRecord) break; //当前页显示完,则退出循环
}
rs.close();
stm.close();
%>
<br>
<tr>
<td align=center colspan="8">
<font size="-1" color=red>
<%
out.print("共"+countRecord+"条新闻,当前第"+dipage+"页,每页"+countPageRecord+"条记录,");
if(dipage==1);//当前是首页
else//当前不是首页
{
out.print("<a href="+request.getContextPath()+"/rczj.jsp?dipage=1><font color=red>首页</font></a>,");
out.print("<a href="+request.getContextPath()+"/rczj.jsp?dipage="+(dipage-1)+"><font color=red>上一页</font></a>,");
}
if(dipage==countPage)//当前是末页
;
else//当前不是末页 yukjyadDD
{ out.print("<a href="+request.getContextPath()+"/rczj.jsp?dipage="+(dipage+1)+"><font color=red>下一页</font></a>,");
out.print("<a href="+request.getContextPath()+"/rczj.jsp?dipage="+countPage+"><font color=red>末页</font></a>");
}
con.close();
%> <%
}catch(SQLException e1)
{
e1.printStackTrace();
}
%>
把响应改动就行!仔细看
别忘了在我的代码后关闭数据库,上面的java代码放在try{}块里,在加上:
catch(SQLException e){e.printStackTrace();}
finally{
rs.close();
smt.close();
con.close();
}
import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%
request.setCharacterEncoding("utf-8");
%>
<%@ page import="log.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<link href="cq.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
ResultSet rs = null;
Log log = new Log();
%>
<%
int pageSize = 10;
int curPage = 1;
int pageCount = 0;
int recordCount = 0;
recordCount = log.getCount();//获得总记录数
pageCount = (recordCount + pageSize - 1) / pageSize;
System.out.println("pageCount"+pageCount);
%>
<center>
<%try{
curPage = Integer.parseInt(request.getParameter("cp"));
}catch(Exception e){}
%><%
System.out.println("curPage"+curPage);
%>
<h2>
操作记录如下
</h2>
<br>
<script language="javaScript">
function openPage(curpage)
{
document.page.cp.value = curpage ;
document.page.submit() ;
}
function selOpenPage()
{
document.spage.cp.value = document.spage.selpage.value ;
document.spage.submit() ;
}
</script>
<form action="log.jsp" name="page">
<input type="button" value="首页" onclick="openPage(1)" <%=curPage==1?"disabled":""%>>
<input type="button" value="上一页" onclick="openPage(<%=curPage-1%>)" <%=curPage==1?"disabled":""%>>
<input type="button" value="下一页" onclick="openPage(<%=curPage+1%>)" <%=curPage==pageCount?"disabled":""%>>
<input type="button" value="尾页" onclick="openPage(<%=pageCount%>)" <%=curPage==pageCount?"disabled":""%>>
<input type="hidden" name="cp" value="">
共<%=pageCount%>页
</form>
<table border="1" width="500">
<tr>
<td>用户ID</td>
<td>操作 </td>
<td>功能 </td>
<td>时间</td>
</tr>
<%
rs=log.getRcord();
int i=0;
for(int x=0;x<(curPage-1)*pageSize;x++){
rs.next();
}
for(int j=0;j<pageSize;j++){
if(rs.next()){
i++;
System.out.println("i"+i);
%>
<tr>
<td><%=rs.getString("USER_ID")%></td>
<td><%=rs.getString("OPER")%></td>
<td><%=rs.getString("FUNC")%></td>
<td><%=rs.getString("LTIME")%></td>
</tr>
<%}
}
if(i==0){
%>
<tr>
<td colspan="4">没有任何数据!!</td>
</tr>
<%}
%>
<tr><td colspan="4">
<a href="article.jsp">返回主界面
</a></td></tr>
</table> </center>
</body>
</html>
http://hi.baidu.com/lovekaili/blog/item/53c745bf92502b0f18d81f13.html