Java WEB 开发典型模块大全中。22/S1中的分页显示
发表在JavaWeb图书答疑
2010-11-11
我按照此例子上的做法引用了分页显示。但是分页总是不成功。我的引用如下:
main_zuoup.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import = "java.util.*" %>
<%@ page import ="zhuye.dao.zixundao"%>
<%@ page import ="zhuye.form.zixunform"%>
<%@ page import = "java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
....
...
...
..
.
...
<!-- 显示分页导航 -->
<table border="0" width="100%" height="40" cellspacing="0" cellpadding="0" style="margin-top:1;margin-bottom:1">
<tr><td><jsp:include page="/pageBar.jsp"/></td></tr>
</table>
上面的是在JSP中因用那个分页导航。
然后我还引用了下面两个文件:
pageBar.jsp和PageBar.java和光盘上给的例子一样。(光盘上的分页显示实例运行时成功的)
tomcat显示如下:
2010-11-11 17:26:10 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded Apache Tomcat Native library 1.1.10.
2010-11-11 17:26:10 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], random [true].
2010-11-11 17:26:10 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2010-11-11 17:26:10 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-8009
2010-11-11 17:26:10 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1347 ms
2010-11-11 17:26:11 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2010-11-11 17:26:11 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.13
2010-11-11 17:26:14 net.fckeditor.connector.ConnectorServlet init
信息: ConnectorServlet successfully initialized!
2010-11-11 17:26:15 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2010-11-11 17:26:15 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2010-11-11 17:26:15 org.apache.catalina.startup.Catalina start
信息: Server startup in 4454 ms
select * from main_PigeonRacingConsulting order by file_uptime
我想是不是需要在哪里配置什么东西或者说我少引用了什么?????
希望能快速回复。
谢谢
remember
学分:0 LV1
TA的每日心情
2024-02-21 17:21:09
你好,因为不是我们书中的代码,我们没有详细的代码,你可以将你的详细代码发上来,以及你的配置过程。我们会给你尽快解决。
baijing1205
学分:0 LV1
TA的每日心情
2022-09-07 16:41:35
PageBar.java代码如下
package com.toolsbean;
public class PageBar {
private int allR; //所有记录数
private int perR; //每页显示记录数
private int perP; //每页显示页码数
private int allP; //共有页数
private int allG; //共有组数
private int currentP=1; //当前页码
private int currentG=1; //当前组号
private String pageLink; //分页导航栏信息
public PageBar(){
allR=0;
perR=5;
perP=5;
currentP=1;
currentG=1;
pageLink="";
}
/** ①-设置总记录数 */
public void setAllR(int allR){
this.allR=allR;
}
/** ②-设置每页显示记录数 */
public void setPerR(int perR){
this.perR=perR;
}
/** ②-设置每页显示页码数 */
public void setPerP(int perP){
this.perP=perP;
}
/** ③-生成分页栏 */
public void setPageBar(String strcurrentP,String strcurrentG,String goWhich){
setAllP(); //计算总页数
setAllG(); //计算总组数
setCurrentP(strcurrentP); //设置当前页码
setCurerntG(strcurrentG); //设置当前组号
setCurrent(); //计算最终的当前页码和当前组号
setPageLink(goWhich); //生成分页导航栏
}
/** ①-计算总页数 */
private void setAllP(){
allP=(allR%perR==0)?(allR/perR):(allR/perR+1);
}
/** ②-计算总组数 */
private void setAllG(){
allG=(allP%perP==0)?(allP/perP):(allP/perP+1);
}
/** ③-设置当前页码 */
private void setCurrentP(String currentP) {
try{
this.currentP=Integer.parseInt(currentP);
}catch(NumberFormatException e){
this.currentP=-1;
}
}
/** ③-设置当前组号 */
private void setCurerntG(String currentG){
try{
this.currentG=Integer.parseInt(currentG);
}catch(Exception e){
this.currentG=-1;
}
}
/** ④-计算最终的当前页和当前组 */
private void setCurrent(){
if(currentP==-1&¤tG==-1){ //传递的currentP和currentG参数不是数字形式
currentP=1;
currentG=1;
}
else if(currentP!=-1&¤tG!=-1){ //同时传递了currentP和currentG参数
currentP=1;
currentG=1;
}
else if(currentP!=-1){ //只传递了cuttentP参数
if(currentP>allP)
currentP=allP;
currentG=(currentP%perP==0)?(currentP/perP):(currentP/perP)+1;
}
else if(currentG!=-1){ //只传递了currentG参数
if(currentG>allG)
currentG=allG;
currentP=(currentG-1)*perP+1;
}
}
/** ⑤-设置分页导航栏信息 */
private void setPageLink(String goWhich){
pageLink="<table border='0' cellpadding='2' cellspacing='0'>";
pageLink+="<tr class='pager'>";
pageLink+="<form action='"+goWhich+"' method='post'>";
pageLink+="<td>";
pageLink+="共("+allR+")记录 共("+allP+")页 ";
pageLink+="<input type='text' name='currentP' size='7'> ";
pageLink+="<input type='submit' value='跳转'>";
pageLink+="</td>";
pageLink+="</form>";
pageLink+="</tr>";
if(goWhich==null)
goWhich="";
if(goWhich.indexOf("?")>=0)
goWhich+="&";
else
goWhich+="?";
pageLink+="<tr class='pager'>";
pageLink+="<td>[";
if(currentG>1)
pageLink+="<a href='"+goWhich+"currentG="+(currentG-1)+"#listtop' class='pagertext'>上"+perP+"页</a> ";
if(currentP>1){
pageLink+="<a href='"+goWhich+"currentP=1#listtop'>首页</a> ";
pageLink+="<a href='"+goWhich+"currentP="+(currentP-1)+"#listtop'>上一页</a> | ";
}
if(currentP%perP==0){ //如果当前页是当前组的最后一页
currentG+=1; //将当前组加1
pageLink+="<a class='pagerCurrentP'>"+currentP+"</a> "; //输出该页码
}
//--start--输出当前组中的页码
int start=(currentG-1)*perP+1; //获取起始页码
for(int i=0;((i<perP)&&((start+i)<=allP));i++){ //通过循环依次输出当前组中的页码
if((start+i)==currentP)
pageLink+="<a class='pagerCurrentP'>"+(start+i)+"</a> ";
else
pageLink+="<a href='"+goWhich+"currentP="+(start+i)+"#listtop' class='pagerline'>"+(start+i)+"</a> ";
}
//--end--
if(currentP<allP){
pageLink+="| <a href='"+goWhich+"currentP="+(currentP+1)+"#listtop'>下一页</a>";
pageLink+=" <a href='"+goWhich+"currentP="+allP+"#listtop'>尾页</a>";
}
if(currentG<allG)
pageLink+=" <a href='"+goWhich+"currentG="+(currentG+1)+"#listtop' class='pagertext'>下"+perP+"页</a>";
pageLink+="]</td>";
pageLink+="</tr>";
pageLink+="</table>";
}
public int getAllR() {
return allR;
}
public int getPerR() {
return perR;
}
public int getPerP() {
return perP;
}
public int getAllP() {
return allP;
}
public int getAllG() {
return allG;
}
public int getCurrentP() {
return currentP;
}
public int getCurrentG() {
return currentG;
}
public String getPageLink() {
return pageLink;
}
}
pageBar.jsp代码如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<c:out value="${requestScope.pageBar.pageLink}" escapeXml="false"/>
Main_zuoup代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import = "java.util.*" %>
<%@ page import ="zhuye.dao.zixundao"%>
<%@ page import ="zhuye.form.zixunform"%>
<%@ page import = "java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<% String contextPath=request.getContextPath(); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> 赛鸽国际</title>
</head>
<body>
<table width="357" height="830" border="0">
<tr>
<td height="37"><img src="images/main_saigezixun.gif" width="357" height="37"></td>
</tr>
<tr>
<td>
<% zixundao zixun= new zixundao();
List list=null;
list = zixun.main_searchzixun();
for(int i = 0 ;i <list.size();i++)
{
zixunform gg = (zixunform)list.get(i);
%>
<table width="355" height="120" border="0">
<tr>
<td width="81" rowspan="2"><img src="files/<%=gg.getId()%>" alt="" name="zixun" width="95" height="109" id="zixun" /></td>
<td width="258" height="29"><%=gg.getFile_title()%></td>
</tr>
<tr>
<td><%=gg.getFile_info()%></td>
</tr>
</table>
<%}%>
</td>
</tr>
<tr><td>
<!-- 显示分页导航 -->
<table border="0" width="100%" height="40" cellspacing="0" cellpadding="0" style="margin-top:1;margin-bottom:1">
<tr><td><jsp:include page="/pageBar.jsp"/></td></tr>
</table>
</td></tr>
</table>
</body>
</html>
baijing1205
学分:0 LV1
TA的每日心情
2022-09-07 16:41:35
这本书上给的源代码如下
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<% String contextPath=request.getContextPath(); %>
<link type="text/css" rel="stylesheet" href="<%=contextPath%>/css/style.css">
<script type="text/javascript" src="<%=contextPath%>/js/visitforum.js"></script>
<body onLoad="changesubsizeshow('tolistcommontopic')">
<center>
<a name="listtop"></a>
<c:set var="topics" value="${requestScope.topicList}"/>
<table border="0" width="100%" style="word-break:break-all" cellpadding="0" cellspacing="1" bgcolor="#8A8989">
<tr height="25" class="listhead">
<td colspan="3" style="text-indent:5;border:0">主题信息</td>
<td align="center" width="17%" style="border:0">楼主</td>
<td align="center" width="7%" style="border:0">回复</td>
<td align="center" width="7%" style="border:0">浏览</td>
<td align="center" width="17%" style="border:0">最后回复</td>
</tr>
<c:if test="${empty topics}">
<tr height="50" bgcolor="#F0F0F0" align="center"><td colspan="7"><b>没有帖子!</b></td></tr>
</c:if>
<c:if test="${!empty topics}">
<!-- 列表显示主题 -->
<c:forEach var="single" varStatus="tvs" items="${topics}">
<c:if test="${tvs.index%2==0}">
<tr bgcolor="#F0F0F0" height="35" align="center"></c:if>
<c:if test="${tvs.index%2!=0}">
<tr bgcolor="white" height="35" align="center"></c:if>
<td width="4%"><img src="<%=contextPath%>/images/icon/topic${single.topicStatus}.gif" style="border:0"></td>
<td width="3%"><img src="<%=contextPath%>/images/emotion/${single.topicEmotion}" style="border:0"></td>
<td align="left" style="text-indent:5;border:0">
<c:if test="${single.topicType eq '1'}"><img src="<%=contextPath%>/images/icon/best.gif" style="border:0"/></c:if>
<c:if test="${single.topicAttachmentSign eq '1'}"><img src="<%=contextPath%>/images/icon/attach.gif" style="border:0"/></c:if>
<a href="<%=contextPath %>/visit/topic/a/view?topicId=${single.id}" target="_blank">${single.topicTitle}</a>
</td>
<td>
<a href="<%=contextPath%>/visit/user/a/viewmember?memberName=${single.topicAuthorName}" class="title" target="_blank">${single.topicAuthorName}</a><br>
${single.topicPostTime}
</td>
<td><b>${single.topicReplyNum}</b></td>
<td><b>${single.topicHits}</b></td>
<td>
<c:if test="${!empty single.lastReply}">
<a href="<%=contextPath%>/visit/user/a/viewmember?memberName=${single.lastReply.replyAuthorName}" class="title" target="_blank">${single.lastReply.replyAuthorName}</a><br>
${single.lastReply.replyReplyTime}
</c:if>
</td>
</tr>
</c:forEach>
</table>
<!-- 显示分页导航 -->
<table border="0" width="100%" cellspacing="0" cellpadding="0" style="margin-top:1;margin-bottom:1">
<tr><td><jsp:include page="/pageBar.jsp"/></td></tr>
</table>
<!-- 显示说明 -->
<table border="0" width="100%" style="margin-top:20;margin-bottom:20">
<tr height="25">
<td align="center" width="20"><img src="<%=contextPath%>/images/icon/best.gif" alt="精华帖子" style="border:0"></td>
<td>精华帖</td>
</tr>
<tr height="25">
<td align="center" width="20"><img src="<%=contextPath%>/images/icon/attach.gif" alt="提供附件" style="border:0"></td>
<td>该主题提供附件下载!</td>
</tr>
<tr>
<td align="center" width="20"><img src="<%=contextPath%>/images/icon/topic2.gif" alt="开放主题" style="border:0"></td>
<td>所有会员可对该主题进行浏览、回复操作以及帖主可进行编辑操作!</td>
</tr>
<tr height="25">
<td align="center" width="20"><img src="<%=contextPath%>/images/icon/topic1.gif" alt="锁定主题" style="border:0"></td>
<td>所有会员只能浏览该主题!</td>
</tr>
</table>
</c:if>
</center>
</body>
其中的PageBar.java和pageBar.jsp同上面代码一样
绿草_mrkj
学分:0 LV1
如果是对书中的代码做了修改,读者可以自己参考书中的内容和光盘自己进行调试,这样也可以到达学习的目的。