| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1396 人关注过本帖
标题:[求助]带参数的分页问题,问题已解决谢谢^_^
只看楼主 加入收藏
暖安丫头
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-9-20
收藏
得分:0 

这个是引用的文件

// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2006-8-10 11:35:20
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: MultiPage.java

package com.cdx.share;

import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

// Referenced classes of package com.cdx.share:
// ConfigManager

public class MultiPage
{

public MultiPage()
{
iTotalSize = 0;
iPageSize = 0;
iPage = 1;
iRowStart = 0;
iRowEnd = 0;
iPageCount = 2;
htUserArea = new Hashtable();
}

public static MultiPage getInstance(HttpServletRequest request)
throws Exception
{
MultiPage cMultiPage;
Object objMultiPage = request.getSession().getAttribute("cMultiPage");
if(objMultiPage == null)
{
cMultiPage = new MultiPage();
request.getSession().setAttribute("cMultiPage", cMultiPage);
} else
{
cMultiPage = (MultiPage)objMultiPage;
}
if(cMultiPage.iPageSize == 0)
{
String SiPageSize = ConfigManager.getValue("PerPageRecordCount");
if(SiPageSize.equals("0"))
SiPageSize = "20";
cMultiPage.iPageSize = Integer.parseInt(SiPageSize);
}
for(Enumeration eKey = cMultiPage.htUserArea.keys(); eKey.hasMoreElements();)
{
String sKey = eKey.nextElement().toString();
Object obj = request.getAttribute(sKey);
if(obj == null)
{
request.setAttribute(sKey, cMultiPage.htUserArea.get(sKey));
} else
{
request.setAttribute(sKey, obj);
cMultiPage.iPage = 1;
}
}

String SiPage = request.getParameter("iPagePara");
if(SiPage == null || SiPage.equals(""))
SiPage = "1";
cMultiPage.iPage = Integer.parseInt(SiPage);
String SiPageSize = request.getParameter("iPageSizePara");
if(SiPageSize != null)
{
cMultiPage.iPageSize = Integer.parseInt(SiPageSize);
int iPages = cMultiPage.iTotalSize / cMultiPage.iPageSize;
if(cMultiPage.iTotalSize % cMultiPage.iPageSize > 0)
iPages++;
if(cMultiPage.iPage > iPages)
cMultiPage.iPage = iPages;
if(cMultiPage.iPage == 0)
cMultiPage.iPage = 1;
}
return cMultiPage;
Exception e;
e;
e.printStackTrace(System.out);
throw e;
}

public String getNavigation(String sURL)
throws Exception
{
return getNavigation(sURL, "");
}

public String getNavigation(String sURL, String sPara)
throws Exception
{
String sReturn;
int iPages = iTotalSize / iPageSize;
if(iTotalSize % iPageSize > 0)
iPages++;
int iPageCountS = iPage - iPageCount;
int iPageCountE = iPage + iPageCount;
if(iPageCountS < iPageCount)
iPageCountE = 2 * iPageCount + 1;
if(iPageCountE > iPages)
iPageCountS = iPages - 2 * iPageCount;
if(iPageCountS < 1)
iPageCountS = 1;
if(iPageCountE > iPages)
iPageCountE = iPages;
sReturn = "<script type=text/javascript>\r\n";
sReturn = sReturn + "function PageShowPage(iPagePara)\r\n";
sReturn = sReturn + "{\r\n";
sReturn = sReturn + " var obj=0; var iPageSizeParaValue=20;\r\n";
sReturn = sReturn + " try{obj=iPageSizePara;}catch(pe){ for(var m=0;m<document.forms.length;m++){ try{obj=document.forms[m]['iPageSizePara'];if(typeof obj == 'object') break;}catch(pe2){}; } };\r\n";
sReturn = sReturn + " if(obj!=0) iPageSizeParaValue=obj.value;\r\n";
sReturn = sReturn + " if(iPageSizeParaValue.length==0)\r\n";
sReturn = sReturn + " {\r\n";
sReturn = sReturn + " alert('\u8BF7\u8F93\u5165\u6BCF\u9875\u663E\u793A\u6570!'); obj.value='" + iPageSize + "';if(obj!=0) obj.focus();\r\n";
sReturn = sReturn + " }\r\n";
sReturn = sReturn + " else \r\n";
sReturn = sReturn + " {";
sReturn = sReturn + " fm.action= '" + sURL + "' ; ";
sReturn = sReturn + " fm.iPagePara.value= iPagePara ;";
sReturn = sReturn + " fm.iPageSizePara.value= iPageSizeParaValue ;";
sReturn = sReturn + " fm.submit() ;";
sReturn = sReturn + " }";
sReturn = sReturn + "}\r\n";
sReturn = sReturn + "function PageCheckNumber(obj) {var varNumbers='0123456789'; for(var i=0;i<obj.value.length;i++){if(obj.value==0 || varNumbers.indexOf(obj.value.charAt(i))==-1){if(obj.name=='iPageSizePara') obj.value='" + iPageSize + "'; else obj.value='" + iPage + "'; alert('\u8BF7\u8F93\u5165\u6B63\u6574\u6570!'); obj.focus(); return false;} } return true;}\r\n";
sReturn = sReturn + "function goPageSize()\r\n";
sReturn = sReturn + "{\r\n";
sReturn = sReturn + " var obj=0; var iPageParaValue=1;\r\n";
sReturn = sReturn + " try{obj=iPagePara;}catch(pe){for(var m=0;m<document.forms.length;m++){try{obj=document.forms[m]['iPagePara'];if(typeof obj == 'object') break;}catch(pe2){};}};\r\n";
sReturn = sReturn + " if(obj!=0) iPageParaValue=obj.value;\r\n";
sReturn = sReturn + " if(iPageParaValue=='') iPageParaValue='" + iPage + "'\r\n";
sReturn = sReturn + " if(iPageParaValue>" + iPages + " || iPageParaValue.length==0)\r\n";
sReturn = sReturn + " {\r\n";
sReturn = sReturn + " alert('\u8BF7\u8F93\u5165\u6570\u5B57\uFF0C\u8303\u56F4\u4E3A: 1 \u5230 " + iPages + " !'); if(obj!=0) obj.focus();\r\n";
sReturn = sReturn + " }\r\n";
sReturn = sReturn + " else\r\n";
sReturn = sReturn + " PageShowPage(iPageParaValue);\r\n";
sReturn = sReturn + "}\r\n";
sReturn = sReturn + "function PageKeyEnterPage(obj) {if(event.keyCode==13) {if(PageCheckNumber(obj) && obj.value!=\"\") goPageSize(); event.cancelBubble=true; event.returnValue=false;} }\r\n";
sReturn = sReturn + "function PageKeyEnterSize(obj) {if(event.keyCode==13) {if(PageCheckNumber(obj) && obj.value!=\"\") goPageSize(); event.cancelBubble=true; event.returnValue=false;} }\r\n";
sReturn = sReturn + "function PageGoPage_onClick() {var iPageParaValue=0;var obj=0; try{iPageParaValue=iPagePara.value;obj=iPagePara;}catch(pe){for(var m=0;m<document.forms.length;m++){try{iPageParaValue=document.forms[m][\"iPagePara\"].value;obj==document.forms[m][\"iPagePara\"];if(typeof obj == 'object') break;}catch(pe2){};}}; if(iPageParaValue!=0) goPageSize(); else if(obj!=0) obj.focus();}\r\n";
sReturn = sReturn + "</script>\r\n";
sReturn = sReturn + "|\u884C\u6570:";
sReturn = sReturn + iTotalSize + "|\u9875\u6570:";
sReturn = sReturn + iPage + "/" + iPages;
sReturn = sReturn + "|&nbsp;";
if(iPage > 1)
{
sReturn = sReturn + "<a href='javascript: PageShowPage(" + 1 + ");'><font face='webdings'>9</font></a>";
sReturn = sReturn + "<a href='javascript: PageShowPage(" + (iPage - 1) + ");'><font face='webdings'>7</font></a>";
} else
{
sReturn = sReturn + "<font color=gray face='webdings'>9</font>";
sReturn = sReturn + "<font color=gray face='webdings'>7</font>";
}
sReturn = sReturn + "&nbsp;";
for(int i = iPageCountS; i <= iPageCountE; i++)
{
if(iPage != i)
sReturn = sReturn + "<a href='javascript: PageShowPage(" + i + ");'>";
else
sReturn = sReturn + "<font color=red>";
sReturn = sReturn + i;
if(iPage != i)
sReturn = sReturn + "</a>\r\n";
else
sReturn = sReturn + "</font>\r\n";
if(i < iPageCountE)
sReturn = sReturn + "&nbsp;";
}

if(iPage < iPages)
{
sReturn = sReturn + "<a href='javascript: PageShowPage(" + (iPage + 1) + ");'><font face='webdings'>8</font></a>";
sReturn = sReturn + "<a href='javascript: PageShowPage(" + iPages + ");'><font face='webdings'>:</font></a>";
} else
{
sReturn = sReturn + "<font color=gray face='webdings'>8</font>";
sReturn = sReturn + "<font color=gray face='webdings'>:</font>";
}
sReturn = sReturn + "&nbsp;|";
sReturn = sReturn + "<a id='PageGoPage' href='javascript: PageGoPage_onClick();'>\u8F6C\u5230</a>";
sReturn = sReturn + "<input name='iPagePara' type='text' style='BACKGROUND: transparence; BORDER-BOTTOM: #BBBBBB 1px solid; BORDER-LEFT: #BBBBBB 0px solid; BORDER-RIGHT: #BBBBBB 0px solid; BORDER-TOP: #BBBBBB 0px solid; FONT-SIZE: 12px; text-align:center' size=2 onkeydown='javascript: PageKeyEnterPage(this);' onblur='javascript: PageCheckNumber(this);event.returnValue=false;'>|";
sReturn = sReturn + "<a href='javascript: goPageSize();'>\u6BCF\u9875</a>";
sReturn = sReturn + "<input name='iPageSizePara' type='text' style='BACKGROUND: transparence; BORDER-BOTTOM: #BBBBBB 1px solid; BORDER-LEFT: #BBBBBB 0px solid; BORDER-RIGHT: #BBBBBB 0px solid; BORDER-TOP: #BBBBBB 0px solid; FONT-SIZE: 12px; text-align:center' size=2 onkeydown='javascript: PageKeyEnterSize(this);' onblur='javascript: PageCheckNumber(this);event.returnValue=false;' value='" + iPageSize + "'>|\r\n";
return sReturn;
Exception e;
e;
throw e;
}

public void setPageData(String key, Object obj)
{
htUserArea.put(key, obj);
}

public Object getPageData(String key)
{
return htUserArea.get(key);
}

public void setTotalSize(int iTotalSize)
{
this.iTotalSize = iTotalSize;
iRowStart = (iPage - 1) * iPageSize;
iRowEnd = iPage * iPageSize;
if(iRowEnd > this.iTotalSize)
iRowEnd = this.iTotalSize;
}

public int getPageSize()
{
return iPageSize;
}

public int getStartRowNo()
{
return iRowStart;
}

public int getEndRowNo()
{
return iRowEnd;
}

public int getTotalSize()
{
return iTotalSize;
}

public int getTotalPages()
{
if(iPageSize == 0)
iPageSize = 1;
int iPages = iTotalSize / iPageSize;
if(iTotalSize % iPageSize > 0)
iPages++;
return iPages;
}

private int iTotalSize;
private int iPageSize;
private int iPage;
private int iRowStart;
private int iRowEnd;
private int iPageCount;
private Hashtable htUserArea;
}

2006-09-22 15:34
wh_calm
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-9-16
收藏
得分:0 
把你的错贴出来看看,ipageSize 换成public的呢
2006-09-22 16:25
暖安丫头
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-9-20
收藏
得分:0 

谢谢大家的热心帮助,我的问题在和同事的讨论中圆满解决,放出解决方案感谢帮助过我的各位高手们

实现功能:多条件组合查询并分页

最后结果如下:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="com.cdx.share.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%DBAccess db=new DBAccess("java:comp/env/jdbc/SLLY");%>
<%request.setCharacterEncoding("GB2312");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>水事纠纷</title>
<LINK href="../css/cssDefault.css" type=text/css rel=stylesheet>
</head>

<body><div><tr>&nbsp;</tr>
<table class=table1 cellspacing="1">

<tr height="20">
<td background="../images/table/bg_line4.jpg" class=td4 colspan=6>
<img src="../images/table/ball.gif">水&nbsp;事&nbsp;纠&nbsp;纷<img src="../images/table/ball.gif"></td></tr>

<form name="fm" method="post" action="DISSENSION.jsp">
<%
String WATERSYSTEM=request.getParameter("WATERSYSTEM");
String D_TYPE=request.getParameter("D_TYPE");
String EA_TIME=request.getParameter("EA_TIME");
String RIVERNAME=request.getParameter("RIVERNAME");
String C_LOCUS=request.getParameter("C_LOCUS");
String D_DATE=request.getParameter("D_DATE");

if ((WATERSYSTEM==null)||(WATERSYSTEM==""))
{
WATERSYSTEM="";
}if ((D_TYPE==null)||(D_TYPE==""))
{
D_TYPE="";
}if ((EA_TIME==null)||(EA_TIME==""))
{
EA_TIME="";
}if ((RIVERNAME==null)||(RIVERNAME==""))
{
RIVERNAME="";
}if ((C_LOCUS==null)||(C_LOCUS==""))
{
C_LOCUS="";
}if ((D_DATE==null)||(D_DATE==""))
{
D_DATE="";
}
%>
<tr>
<td class=td3>选择河系</td>
<td class=td2>
<select name="WATERSYSTEM" class=select2>
<option value="<%=WATERSYSTEM%>" selected><%=WATERSYSTEM%></option>
<option value="黑龙江水系">黑龙江水系</option>
<option value="乌苏里江水系">乌苏里江水系</option>
<option value="绥芬河水系">绥芬河水系</option>
<option value="图们江水系">图们江水系</option>
<option value="额尔古纳河水系">额尔古纳河水系</option>
<option value="鸭绿江水系">鸭绿江水系</option>
<option value="其它(界湖)">其它(界湖)</option>
</select></td>
<td class=td3>选择类别</td>
<td class=td2>
<SELECT NAME="D_TYPE" class=select2>
<option value="<%=D_TYPE%>" selected><%=D_TYPE%></option>
<option value="水事纠纷">水事纠纷</option>
<option value="非水事纠纷">非水事纠纷</option>
</SELECT></td>
<td class=td3>审批时间</td>
<td class=td2><input class=text3 type="text" name="EA_TIME" value="<%=EA_TIME%>"></td>
</tr>
<tr>
<td class=td3>河流名称</td>
<td class=td2><input class=text3 type="text" name="RIVERNAME" value="<%=RIVERNAME%>"></td>
<td class=td3>所在县市</td>
<td class=td2><input class=text3 type="text" name="C_LOCUS" value="<%=C_LOCUS%>"></td>
<td class=td3>时间</td>
<td class=td2><input class=text3 type="text" name="D_DATE" value="<%=D_DATE%>"></td>
</tr>
<tr class=trbottom>
<td colspan="6">
<input name=Submit type=image "img src="../images/button/btnQuery.gif" border="0">
<a href="DISSENSION_register.jsp"><img src="../images/button/btnAdd.gif" border="0"></a>
<input name=Back type=image "img src="../images/button/btnBack.gif" onClick="history.back(-1)" border="0"></td>
</tr>
</table>


<table class=table1 cellspacing="1">
<tr height="20">
<td background="images/table/bg_line4.jpg" class=td4 colspan=6>水事纠纷信息表</td>
</tr>

<tr class=trhead>
<td width="16%">河流名称</td>
<td width="18%">所在县市</td>
<td width="18%">时间</td>
<td width="18%">类型</td>
<td width="15%">照会内容</td>
<td width="15%">备注</td>
</tr>
<%
//添加翻页
int i=0;
MultiPage mp = MultiPage.getInstance(request);
ArrayList al = new ArrayList();//数组
ArrayList altemp = new ArrayList();

StringBuffer sql=new StringBuffer("select * from T_DISSENSION t where 1=1 ");

if (WATERSYSTEM!=null&&!"".equals(WATERSYSTEM))
sql.append(" and t.WATERSYSTEM='"+WATERSYSTEM+"'");
if (D_TYPE!=null&&!"".equals(D_TYPE))
sql.append(" and t.D_TYPE='"+D_TYPE+"'");
if (EA_TIME!=null&&!"".equals(EA_TIME))
sql.append(" and t.EA_TIME='"+EA_TIME+"'");
if (RIVERNAME!=null&&!"".equals(RIVERNAME))
sql.append(" and t.RIVERNAME='"+RIVERNAME+"'");
if (C_LOCUS!=null&&!"".equals(C_LOCUS))
sql.append(" and t.C_LOCUS='"+C_LOCUS+"'");
if (D_DATE!=null&&!"".equals(D_DATE))
sql.append(" and t.D_DATE='"+D_DATE+"'" );

al=db.executeQuery(sql.toString());

mp.setPageData("cny",al);
al = (ArrayList)mp.getPageData("cny");
mp.setTotalSize(al.size());

for (i=mp.getStartRowNo();i<mp.getEndRowNo();i++){

altemp = (ArrayList)al.get(i);
%>
<tr class='<%=(i%2==0)?"tr1":"tr2"%>'><!--三目运算符-->
<td><a href="DISSENSION2.jsp?ID=<%=altemp.get(13)%>"><%=altemp.get(1)%></a></td>
<td><%=altemp.get(3)%></td>
<td><%=altemp.get(8)%></td>
<td><%=altemp.get(4)%></td>
<td><%=altemp.get(10)%></td>
<td><%=altemp.get(12)%></td>
</tr>
<%}%>
<tr class=trbottom>
<td colspan="6"><%=mp.getNavigation("DISSENSION.jsp")%></td>
</tr>

</table></form>
</body>
</html>

2006-09-22 17:22
左岸
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2004-11-25
收藏
得分:0 

吾将尽吾毕生之精力,寻求吾唯一之精神伴侣.得之,吾幸,不得,吾命.....
2006-09-22 21:06
zplove
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:783
专家分:0
注 册:2006-7-30
收藏
得分:0 

给你发个我的分页
<%
int PageSize; //一页显示的记录数
int RowCount; //记录总数
int PageCount; //总页数
int intPage; //待显示页码
String strPage;
int i;
PageSize =3; //设置一页显示的记录数
strPage = request.getParameter("page"); //取得待显示页码
if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}else{//将字符串转换成整型
intPage = Integer.parseInt(strPage);
}
if(intPage<1) {
intPage = 1;
}
rs.last();//光标在最后一行
RowCount = rs.getRow();//获得当前行号
PageCount = (RowCount+PageSize-1) / PageSize; //记算总页数
if(intPage>PageCount){
intPage = PageCount; //调整待显示的页码
}else if(PageCount>0){
rs.absolute((intPage-1) * PageSize + 1); //将记录指针定位到待显示页的第一条记录上
i = 0; //显示数据

while(i<PageSize && !rs.isAfterLast()){


%>
第<%=intPage%>页 共<%=PageCount%>页
<%if(intPage<PageCount){%>
<a href="teacher.jsp?page=<%=intPage+1%>">下一页</a>
<%}%>
<%if(intPage>1){%>
<a href="teacher.jsp?page=<%=intPage-1%>">上一页</a>
<%}%>


相信自己的没错了
2006-09-23 08:41
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
希望你需要分页的内容不多,楼上的做法否则会死人的....
mysql有专门的分页语句 limit
其他数据库都有相关的分页语句,但是偶是不知道了.如果用hibernate就可以屏蔽掉这些差别.


恩,好久不来了,一来就灌水,见谅

淘宝杜琨
2006-09-23 08:46
快速回复:[求助]带参数的分页问题,问题已解决谢谢^_^
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.106179 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved