<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=GBK
"
pageEncoding = " GBK " %>
<% @ page import = " com.accp.Bean.*,com.accp.Dao.*,java.util.* " %>
< html >
< head >
< style >
table{font - size:14px}
A{text - decoration:none;}
A:hover{color:blue}
</ style >
< title > Insert title here </ title >
< script language = " javaScript " >
function Jumping(){
document.PageForm.submit();
return ;
}
function gotoPage(pagenum){
document.PageForm.jumpPage.value = pagenum;
document.PageForm.submit();
return ;
}
</ script >
< style >
form{font - size:13px}
</ style >
</ head >
<% StringPager pager = new StringPager();
TopicDao dao = new TopicDao();
List lst = dao.selectAll();
pager.setTopicSelect(lst); // 需要分页的文本
pager.setSizePerPage( 5 ); // 每页显示行数
int curPage; // 当前是第几页
int maxPage; // 一共有多少页
curPage = 1 ; // 当前页
maxPage = pager.getTotalPage();
String jumpPage = (String)request.getParameter( " jumpPage " );
if (jumpPage != null && ! jumpPage.equals( "" )){
curPage = Integer.parseInt(jumpPage);
}
pager.setCurrentPage(curPage);
%>
< body >
< br >< br >
< p align = " center " >< font size = " 5 " > 欢迎进入帖子管理页面 </ font ></ p >
< form name = " PageForm " action = "" method = " post " >
< table align = " center " width = " 650 " bgcolor = " #FFFFFF " >
< tr >< td colspan = " 3 " > 每页 <%= pager.getSizePerPage() %> 条
第 <%= curPage %> 页
共 <%= maxPage %> 页 </ td >
< td colspan = " 2 " align = " right " >
<% if (curPage == 1 ){
out.print( " 首页 上一页 " );
} else { %>
< A HREF = " javascript:gotoPage(1) " > 首页 </ A >
< A HREF = " javascript:gotoPage(<%=curPage-1%>) " > 上一页 </ A >
<% } %>
<% if (curPage == maxPage){
out.print( " 下一页 尾页 " );
} else { %>
< A HREF = " javascript:gotoPage(<%=curPage+1%>) " > 下一页 </ A >
< A HREF = " javascript:gotoPage(<%=maxPage%>) " > 尾页 </ A >
<% } %>
转到第 < SELECT name = " jumpPage " onchange = " Jumping() " >
<% for ( int i = 1 ;i <= maxPage;i ++ ) {
if (i == curPage){
%>
< OPTION selected value =<%= i %>><%= i %></ OPTION >
<% } else { %>
< OPTION value =<%= i %>><%= i %></ OPTION >
<% }} %>
</ SELECT > 页 </ td ></ tr >
< tr bgcolor = " #C0C0C0 " align = " center " >
< td > 序号 </ td >
< td > 标题 </ td >
< td > 内容 </ td >
< td > 积分 </ td >
< td > 等级 </ td >
</ tr >
<%
for ( int i = 0 ;i < pager.getCurrentPagedText().size();i ++ ){
Topic topic = (Topic)(pager.getCurrentPagedText().get(i));
%>
< tr bgcolor = " #C0C0C0 " align = " center " >
< td ><%= topic.getId() %></ td >
< td ><%= subStr(topic.getTitle()) %></ td >
< td ><%= subStr(topic.getConter()) %></ td >
< td ><%= topic.getIntegral() %></ td >
< td ><%= topic.getGrade() %></ td >
</ tr >
<% } %>
<%!
// 截取字符串方法
public String subStr(String str){
if (str == null || "" .equals(str)){
return "" ;
}
if (str.length() > 8 ){
return str.substring( 0 , 8 ) + " " ;
} else {
return str;
}
}
%>
</ table >
</ form >
</ body >
</ html >
pageEncoding = " GBK " %>
<% @ page import = " com.accp.Bean.*,com.accp.Dao.*,java.util.* " %>
< html >
< head >
< style >
table{font - size:14px}
A{text - decoration:none;}
A:hover{color:blue}
</ style >
< title > Insert title here </ title >
< script language = " javaScript " >
function Jumping(){
document.PageForm.submit();
return ;
}
function gotoPage(pagenum){
document.PageForm.jumpPage.value = pagenum;
document.PageForm.submit();
return ;
}
</ script >
< style >
form{font - size:13px}
</ style >
</ head >
<% StringPager pager = new StringPager();
TopicDao dao = new TopicDao();
List lst = dao.selectAll();
pager.setTopicSelect(lst); // 需要分页的文本
pager.setSizePerPage( 5 ); // 每页显示行数
int curPage; // 当前是第几页
int maxPage; // 一共有多少页
curPage = 1 ; // 当前页
maxPage = pager.getTotalPage();
String jumpPage = (String)request.getParameter( " jumpPage " );
if (jumpPage != null && ! jumpPage.equals( "" )){
curPage = Integer.parseInt(jumpPage);
}
pager.setCurrentPage(curPage);
%>
< body >
< br >< br >
< p align = " center " >< font size = " 5 " > 欢迎进入帖子管理页面 </ font ></ p >
< form name = " PageForm " action = "" method = " post " >
< table align = " center " width = " 650 " bgcolor = " #FFFFFF " >
< tr >< td colspan = " 3 " > 每页 <%= pager.getSizePerPage() %> 条
第 <%= curPage %> 页
共 <%= maxPage %> 页 </ td >
< td colspan = " 2 " align = " right " >
<% if (curPage == 1 ){
out.print( " 首页 上一页 " );
} else { %>
< A HREF = " javascript:gotoPage(1) " > 首页 </ A >
< A HREF = " javascript:gotoPage(<%=curPage-1%>) " > 上一页 </ A >
<% } %>
<% if (curPage == maxPage){
out.print( " 下一页 尾页 " );
} else { %>
< A HREF = " javascript:gotoPage(<%=curPage+1%>) " > 下一页 </ A >
< A HREF = " javascript:gotoPage(<%=maxPage%>) " > 尾页 </ A >
<% } %>
转到第 < SELECT name = " jumpPage " onchange = " Jumping() " >
<% for ( int i = 1 ;i <= maxPage;i ++ ) {
if (i == curPage){
%>
< OPTION selected value =<%= i %>><%= i %></ OPTION >
<% } else { %>
< OPTION value =<%= i %>><%= i %></ OPTION >
<% }} %>
</ SELECT > 页 </ td ></ tr >
< tr bgcolor = " #C0C0C0 " align = " center " >
< td > 序号 </ td >
< td > 标题 </ td >
< td > 内容 </ td >
< td > 积分 </ td >
< td > 等级 </ td >
</ tr >
<%
for ( int i = 0 ;i < pager.getCurrentPagedText().size();i ++ ){
Topic topic = (Topic)(pager.getCurrentPagedText().get(i));
%>
< tr bgcolor = " #C0C0C0 " align = " center " >
< td ><%= topic.getId() %></ td >
< td ><%= subStr(topic.getTitle()) %></ td >
< td ><%= subStr(topic.getConter()) %></ td >
< td ><%= topic.getIntegral() %></ td >
< td ><%= topic.getGrade() %></ td >
</ tr >
<% } %>
<%!
// 截取字符串方法
public String subStr(String str){
if (str == null || "" .equals(str)){
return "" ;
}
if (str.length() > 8 ){
return str.substring( 0 , 8 ) + " " ;
} else {
return str;
}
}
%>
</ table >
</ form >
</ body >
</ html >
package
examples;
/*
* @(#)StringPager.java 1.00 2004-10-10
*
* Copyright 2004 . All rights reserved.
* PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/**
* StringPager, 字符串分页.
*
* @author xxxxxx
* @version 1.00 2004-10-10
*/
public class StringPager {
/** 当前页码数 */
private int currentPage = 1 ;
/** 需要分页的长字符串 */
private String text;
/** 每页显示字符数, 默认为 200 */
private int sizePerPage = 200 ;
/** 总页数 */
private int totalPage;
public StringPager() {}
/**
* 返回当前页的字符串.
* @return
*/
public String getCurrentPagedText() {
try {
if (getCurrentPage() < getTotalPage()) {
return getText().substring((getCurrentPage() - 1 ) * getSizePerPage(),
getCurrentPage() * getSizePerPage());
} else if (getTotalPage() > 0 ) {
return getText().substring((getCurrentPage() - 1 ) * getSizePerPage());
}
} catch (Exception e) {
e.printStackTrace();
}
return null ;
}
/**
* @return Returns the 当前页码数.
*/
public int getCurrentPage() {
if (currentPage <= 0 ) currentPage = 1 ;
return currentPage;
}
/**
* 设置当前页码, 从 1 开始.
*
* @param currentPage
* The 当前页码数 to set.
*/
public void setCurrentPage( int currentPage) {
if (currentPage <= 0 ) {
currentPage = 1 ;
}
this .currentPage = currentPage;
}
/**
* @return Returns the 总页码数, 如果没有数据, 就返回 1.
*/
public int getTotalPage() {
if (getText() == null ) totalPage = 0 ;
totalPage = ( int ) Math.ceil( 1.0 * getText().length() / getSizePerPage()); // 总页面数
if (totalPage == 0 )
totalPage = 1 ;
return totalPage;
}
/**
* @param totalPage
* The totalPage to set.
*/
public void setTotalPage( int totalPage) {
this .totalPage = totalPage;
}
public static void main(String[] args) {
StringPager pager = new StringPager();
pager.setSizePerPage( 5 );
pager.setText( " 12345678901 " );
pager.setCurrentPage( 2 );
System.out.println(pager.getTotalPage());
System.out.println(pager.getCurrentPagedText());
}
/**
* @return Returns the 每页显示字符数.
*/
public int getSizePerPage() {
return sizePerPage;
}
/**
* @param sizePerPage
* The 每页显示字符数 to set.
*/
public void setSizePerPage( int sizePerPage) {
this .sizePerPage = sizePerPage;
}
/**
* @return Returns the 需要分页的长字符串.
*/
public String getText() {
return text;
}
/**
* @param text
* The 需要分页的长字符串 to set.
*/
public void setText(String text) {
this .text = text;
}
}
/*
* @(#)StringPager.java 1.00 2004-10-10
*
* Copyright 2004 . All rights reserved.
* PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/**
* StringPager, 字符串分页.
*
* @author xxxxxx
* @version 1.00 2004-10-10
*/
public class StringPager {
/** 当前页码数 */
private int currentPage = 1 ;
/** 需要分页的长字符串 */
private String text;
/** 每页显示字符数, 默认为 200 */
private int sizePerPage = 200 ;
/** 总页数 */
private int totalPage;
public StringPager() {}
/**
* 返回当前页的字符串.
* @return
*/
public String getCurrentPagedText() {
try {
if (getCurrentPage() < getTotalPage()) {
return getText().substring((getCurrentPage() - 1 ) * getSizePerPage(),
getCurrentPage() * getSizePerPage());
} else if (getTotalPage() > 0 ) {
return getText().substring((getCurrentPage() - 1 ) * getSizePerPage());
}
} catch (Exception e) {
e.printStackTrace();
}
return null ;
}
/**
* @return Returns the 当前页码数.
*/
public int getCurrentPage() {
if (currentPage <= 0 ) currentPage = 1 ;
return currentPage;
}
/**
* 设置当前页码, 从 1 开始.
*
* @param currentPage
* The 当前页码数 to set.
*/
public void setCurrentPage( int currentPage) {
if (currentPage <= 0 ) {
currentPage = 1 ;
}
this .currentPage = currentPage;
}
/**
* @return Returns the 总页码数, 如果没有数据, 就返回 1.
*/
public int getTotalPage() {
if (getText() == null ) totalPage = 0 ;
totalPage = ( int ) Math.ceil( 1.0 * getText().length() / getSizePerPage()); // 总页面数
if (totalPage == 0 )
totalPage = 1 ;
return totalPage;
}
/**
* @param totalPage
* The totalPage to set.
*/
public void setTotalPage( int totalPage) {
this .totalPage = totalPage;
}
public static void main(String[] args) {
StringPager pager = new StringPager();
pager.setSizePerPage( 5 );
pager.setText( " 12345678901 " );
pager.setCurrentPage( 2 );
System.out.println(pager.getTotalPage());
System.out.println(pager.getCurrentPagedText());
}
/**
* @return Returns the 每页显示字符数.
*/
public int getSizePerPage() {
return sizePerPage;
}
/**
* @param sizePerPage
* The 每页显示字符数 to set.
*/
public void setSizePerPage( int sizePerPage) {
this .sizePerPage = sizePerPage;
}
/**
* @return Returns the 需要分页的长字符串.
*/
public String getText() {
return text;
}
/**
* @param text
* The 需要分页的长字符串 to set.
*/
public void setText(String text) {
this .text = text;
}
}
<%
@ page
import
=
"
examples.*
"
%>
<% @ page contentType = " text/html;charset=gb2312 " %>
< script language = " javaScript " >
function Jumping(){
document.PageForm.submit();
return ;
}
function gotoPage(pagenum){
document.PageForm.jumpPage.value = pagenum;
document.PageForm.submit();
return ;
}
</ script >
<%
StringPager pager = new StringPager();
pager.setText( " 12345678wfasdfae3fgsffd34235534634gfsfd65sfgssaeweasdfa901 " ); // 需要分页的长文本
pager.setSizePerPage( 5 ); // 每页显示字符数
int curPage; // 当前是第几页
int maxPage; // 一共有多少页
curPage = 1 ; // 当前页
maxPage = pager.getTotalPage();
String jumpPage = (String)request.getParameter( " jumpPage " );
if (jumpPage != null && ! jumpPage.equals( "" )){
curPage = Integer.parseInt(jumpPage);
}
pager.setCurrentPage(curPage);
out.println( " 第 " + curPage + " 页<br> " );
out.println(pager.getCurrentPagedText()); // 当前页的字符串
%>
< form name = " PageForm " action = "" method = " post " >
每页 <%= pager.getSizePerPage() %> 字
第 <%= curPage %> 页
共 <%= maxPage %> 页
< BR >
<% if (curPage == 1 ){ out.print( " 首页 上一页 " ); } else { %>
< A HREF = " javascript:gotoPage(1) " > 首页 </ A >
< A HREF = " javascript:gotoPage(<%=curPage-1%>) " > 上一页 </ A >
<% } %>
<% if (curPage == maxPage){ out.print( " 下一页 尾页 " ); } else { %>
< A HREF = " javascript:gotoPage(<%=curPage+1%>) " > 下一页 </ A >
< A HREF = " javascript:gotoPage(<%=maxPage%>) " > 尾页 </ A >
<% } %>
转到第 < SELECT name = " jumpPage " onchange = " Jumping() " >
<% for ( int i = 1 ;i <= maxPage;i ++ ) {
if (i == curPage){
%>
< OPTION selected value =<%= i %>><%= i %></ OPTION >
<% } else { %>
< OPTION value =<%= i %>><%= i %></ OPTION >
<% }} %>
</ SELECT > 页
</ form >
第二种方法:
jsp代码
<% @ page contentType = " text/html;charset=gb2312 " %>
< script language = " javaScript " >
function Jumping(){
document.PageForm.submit();
return ;
}
function gotoPage(pagenum){
document.PageForm.jumpPage.value = pagenum;
document.PageForm.submit();
return ;
}
</ script >
<%
StringPager pager = new StringPager();
pager.setText( " 12345678wfasdfae3fgsffd34235534634gfsfd65sfgssaeweasdfa901 " ); // 需要分页的长文本
pager.setSizePerPage( 5 ); // 每页显示字符数
int curPage; // 当前是第几页
int maxPage; // 一共有多少页
curPage = 1 ; // 当前页
maxPage = pager.getTotalPage();
String jumpPage = (String)request.getParameter( " jumpPage " );
if (jumpPage != null && ! jumpPage.equals( "" )){
curPage = Integer.parseInt(jumpPage);
}
pager.setCurrentPage(curPage);
out.println( " 第 " + curPage + " 页<br> " );
out.println(pager.getCurrentPagedText()); // 当前页的字符串
%>
< form name = " PageForm " action = "" method = " post " >
每页 <%= pager.getSizePerPage() %> 字
第 <%= curPage %> 页
共 <%= maxPage %> 页
< BR >
<% if (curPage == 1 ){ out.print( " 首页 上一页 " ); } else { %>
< A HREF = " javascript:gotoPage(1) " > 首页 </ A >
< A HREF = " javascript:gotoPage(<%=curPage-1%>) " > 上一页 </ A >
<% } %>
<% if (curPage == maxPage){ out.print( " 下一页 尾页 " ); } else { %>
< A HREF = " javascript:gotoPage(<%=curPage+1%>) " > 下一页 </ A >
< A HREF = " javascript:gotoPage(<%=maxPage%>) " > 尾页 </ A >
<% } %>
转到第 < SELECT name = " jumpPage " onchange = " Jumping() " >
<% for ( int i = 1 ;i <= maxPage;i ++ ) {
if (i == curPage){
%>
< OPTION selected value =<%= i %>><%= i %></ OPTION >
<% } else { %>
< OPTION value =<%= i %>><%= i %></ OPTION >
<% }} %>
</ SELECT > 页
</ form >
第二种方法:
package
com.accp.Bean;
import java.util. * ;
public class StringPager {
/** 当前页码数 */
private int currentPage = 1 ;
/** 每页显示行数, 默认为 200 */
private int sizePerPage = 5 ;
/** 总页数 */
private int totalPage;
/** 需要分页的长字符串 */
private List topicSelect;
public StringPager() {
}
/**
* 返回当前页的文本
*
* @return
*/
public List getCurrentPagedText() {
try {
if (getCurrentPage() < getTotalPage()) {
return getTopicSelect().subList(
(getCurrentPage() - 1 ) * getSizePerPage(),getCurrentPage() * getSizePerPage());
} else if (getTotalPage() > 0 ) {
return getTopicSelect().subList((getCurrentPage() - 1 ) * getSizePerPage(),getTopicSelect().size());
}
} catch (Exception e) {
e.printStackTrace();
}
return null ;
}
/**
* @return Returns the 当前页码数.
*/
public int getCurrentPage() {
if (currentPage <= 0 )
currentPage = 1 ;
return currentPage;
}
/**
* 设置当前页码, 从 1 开始.
*
* @param currentPage
* The 当前页码数 to set.
*/
public void setCurrentPage( int currentPage) {
if (currentPage <= 0 ) {
currentPage = 1 ;
}
this .currentPage = currentPage;
}
/**
* @return Returns the 总页码数, 如果没有数据, 就返回 1.
*/
public int getTotalPage() {
if (getTopicSelect() == null )
totalPage = 0 ;
totalPage = ( int ) Math.ceil( 1.0 * getTopicSelect().size()
/ getSizePerPage()); // 总页面数
if (totalPage == 0 )
totalPage = 1 ;
return totalPage;
}
/**
* @param totalPage
* The totalPage to set.
*/
public void setTotalPage( int totalPage) {
this .totalPage = totalPage;
}
/**
* @return Returns the 每页显示行数.
*/
public int getSizePerPage() {
return sizePerPage;
}
/**
* @param sizePerPage
* The 每页显示行数to set.
*/
public void setSizePerPage( int sizePerPage) {
this .sizePerPage = sizePerPage;
}
/**
* @return Returns the 需要分页的文本.
*/
public List getTopicSelect() {
return topicSelect;
}
public void setTopicSelect(List topicSelect) {
this .topicSelect = topicSelect;
}
}
import java.util. * ;
public class StringPager {
/** 当前页码数 */
private int currentPage = 1 ;
/** 每页显示行数, 默认为 200 */
private int sizePerPage = 5 ;
/** 总页数 */
private int totalPage;
/** 需要分页的长字符串 */
private List topicSelect;
public StringPager() {
}
/**
* 返回当前页的文本
*
* @return
*/
public List getCurrentPagedText() {
try {
if (getCurrentPage() < getTotalPage()) {
return getTopicSelect().subList(
(getCurrentPage() - 1 ) * getSizePerPage(),getCurrentPage() * getSizePerPage());
} else if (getTotalPage() > 0 ) {
return getTopicSelect().subList((getCurrentPage() - 1 ) * getSizePerPage(),getTopicSelect().size());
}
} catch (Exception e) {
e.printStackTrace();
}
return null ;
}
/**
* @return Returns the 当前页码数.
*/
public int getCurrentPage() {
if (currentPage <= 0 )
currentPage = 1 ;
return currentPage;
}
/**
* 设置当前页码, 从 1 开始.
*
* @param currentPage
* The 当前页码数 to set.
*/
public void setCurrentPage( int currentPage) {
if (currentPage <= 0 ) {
currentPage = 1 ;
}
this .currentPage = currentPage;
}
/**
* @return Returns the 总页码数, 如果没有数据, 就返回 1.
*/
public int getTotalPage() {
if (getTopicSelect() == null )
totalPage = 0 ;
totalPage = ( int ) Math.ceil( 1.0 * getTopicSelect().size()
/ getSizePerPage()); // 总页面数
if (totalPage == 0 )
totalPage = 1 ;
return totalPage;
}
/**
* @param totalPage
* The totalPage to set.
*/
public void setTotalPage( int totalPage) {
this .totalPage = totalPage;
}
/**
* @return Returns the 每页显示行数.
*/
public int getSizePerPage() {
return sizePerPage;
}
/**
* @param sizePerPage
* The 每页显示行数to set.
*/
public void setSizePerPage( int sizePerPage) {
this .sizePerPage = sizePerPage;
}
/**
* @return Returns the 需要分页的文本.
*/
public List getTopicSelect() {
return topicSelect;
}
public void setTopicSelect(List topicSelect) {
this .topicSelect = topicSelect;
}
}
jsp代码
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=GBK
"
pageEncoding = " GBK " %>
<% @ page import = " com.accp.Bean.*,com.accp.Dao.*,java.util.* " %>
< html >
< head >
< style >
table{font - size:14px}
A{text - decoration:none;}
A:hover{color:blue}
</ style >
< title > Insert title here </ title >
< script language = " javaScript " >
function Jumping(){
document.PageForm.submit();
return ;
}
function gotoPage(pagenum){
document.PageForm.jumpPage.value = pagenum;
document.PageForm.submit();
return ;
}
</ script >
< style >
form{font - size:13px}
</ style >
</ head >
<% StringPager pager = new StringPager();
TopicDao dao = new TopicDao();
List lst = dao.selectAll();
pager.setTopicSelect(lst); // 需要分页的文本
pager.setSizePerPage( 5 ); // 每页显示行数
int curPage; // 当前是第几页
int maxPage; // 一共有多少页
curPage = 1 ; // 当前页
maxPage = pager.getTotalPage();
String jumpPage = (String)request.getParameter( " jumpPage " );
if (jumpPage != null && ! jumpPage.equals( "" )){
curPage = Integer.parseInt(jumpPage);
}
pager.setCurrentPage(curPage);
%>
< body >
< br >< br >
< p align = " center " >< font size = " 5 " > 欢迎进入帖子管理页面 </ font ></ p >
< form name = " PageForm " action = "" method = " post " >
< table align = " center " width = " 650 " bgcolor = " #FFFFFF " >
< tr >< td colspan = " 3 " > 每页 <%= pager.getSizePerPage() %> 条
第 <%= curPage %> 页
共 <%= maxPage %> 页 </ td >
< td colspan = " 2 " align = " right " >
<% if (curPage == 1 ){
out.print( " 首页 上一页 " );
} else { %>
< A HREF = " javascript:gotoPage(1) " > 首页 </ A >
< A HREF = " javascript:gotoPage(<%=curPage-1%>) " > 上一页 </ A >
<% } %>
<% if (curPage == maxPage){
out.print( " 下一页 尾页 " );
} else { %>
< A HREF = " javascript:gotoPage(<%=curPage+1%>) " > 下一页 </ A >
< A HREF = " javascript:gotoPage(<%=maxPage%>) " > 尾页 </ A >
<% } %>
转到第 < SELECT name = " jumpPage " onchange = " Jumping() " >
<% for ( int i = 1 ;i <= maxPage;i ++ ) {
if (i == curPage){
%>
< OPTION selected value =<%= i %>><%= i %></ OPTION >
<% } else { %>
< OPTION value =<%= i %>><%= i %></ OPTION >
<% }} %>
</ SELECT > 页 </ td ></ tr >
< tr bgcolor = " #C0C0C0 " align = " center " >
< td > 序号 </ td >
< td > 标题 </ td >
< td > 内容 </ td >
< td > 积分 </ td >
< td > 等级 </ td >
</ tr >
<%
for ( int i = 0 ;i < pager.getCurrentPagedText().size();i ++ ){
Topic topic = (Topic)(pager.getCurrentPagedText().get(i));
%>
< tr bgcolor = " #C0C0C0 " align = " center " >
< td ><%= topic.getId() %></ td >
< td ><%= subStr(topic.getTitle()) %></ td >
< td ><%= subStr(topic.getConter()) %></ td >
< td ><%= topic.getIntegral() %></ td >
< td ><%= topic.getGrade() %></ td >
</ tr >
<% } %>
<%!
// 截取字符串方法
public String subStr(String str){
if (str == null || "" .equals(str)){
return "" ;
}
if (str.length() > 8 ){
return str.substring( 0 , 8 ) + " " ;
} else {
return str;
}
}
%>
</ table >
</ form >
</ body >
</ html >
pageEncoding = " GBK " %>
<% @ page import = " com.accp.Bean.*,com.accp.Dao.*,java.util.* " %>
< html >
< head >
< style >
table{font - size:14px}
A{text - decoration:none;}
A:hover{color:blue}
</ style >
< title > Insert title here </ title >
< script language = " javaScript " >
function Jumping(){
document.PageForm.submit();
return ;
}
function gotoPage(pagenum){
document.PageForm.jumpPage.value = pagenum;
document.PageForm.submit();
return ;
}
</ script >
< style >
form{font - size:13px}
</ style >
</ head >
<% StringPager pager = new StringPager();
TopicDao dao = new TopicDao();
List lst = dao.selectAll();
pager.setTopicSelect(lst); // 需要分页的文本
pager.setSizePerPage( 5 ); // 每页显示行数
int curPage; // 当前是第几页
int maxPage; // 一共有多少页
curPage = 1 ; // 当前页
maxPage = pager.getTotalPage();
String jumpPage = (String)request.getParameter( " jumpPage " );
if (jumpPage != null && ! jumpPage.equals( "" )){
curPage = Integer.parseInt(jumpPage);
}
pager.setCurrentPage(curPage);
%>
< body >
< br >< br >
< p align = " center " >< font size = " 5 " > 欢迎进入帖子管理页面 </ font ></ p >
< form name = " PageForm " action = "" method = " post " >
< table align = " center " width = " 650 " bgcolor = " #FFFFFF " >
< tr >< td colspan = " 3 " > 每页 <%= pager.getSizePerPage() %> 条
第 <%= curPage %> 页
共 <%= maxPage %> 页 </ td >
< td colspan = " 2 " align = " right " >
<% if (curPage == 1 ){
out.print( " 首页 上一页 " );
} else { %>
< A HREF = " javascript:gotoPage(1) " > 首页 </ A >
< A HREF = " javascript:gotoPage(<%=curPage-1%>) " > 上一页 </ A >
<% } %>
<% if (curPage == maxPage){
out.print( " 下一页 尾页 " );
} else { %>
< A HREF = " javascript:gotoPage(<%=curPage+1%>) " > 下一页 </ A >
< A HREF = " javascript:gotoPage(<%=maxPage%>) " > 尾页 </ A >
<% } %>
转到第 < SELECT name = " jumpPage " onchange = " Jumping() " >
<% for ( int i = 1 ;i <= maxPage;i ++ ) {
if (i == curPage){
%>
< OPTION selected value =<%= i %>><%= i %></ OPTION >
<% } else { %>
< OPTION value =<%= i %>><%= i %></ OPTION >
<% }} %>
</ SELECT > 页 </ td ></ tr >
< tr bgcolor = " #C0C0C0 " align = " center " >
< td > 序号 </ td >
< td > 标题 </ td >
< td > 内容 </ td >
< td > 积分 </ td >
< td > 等级 </ td >
</ tr >
<%
for ( int i = 0 ;i < pager.getCurrentPagedText().size();i ++ ){
Topic topic = (Topic)(pager.getCurrentPagedText().get(i));
%>
< tr bgcolor = " #C0C0C0 " align = " center " >
< td ><%= topic.getId() %></ td >
< td ><%= subStr(topic.getTitle()) %></ td >
< td ><%= subStr(topic.getConter()) %></ td >
< td ><%= topic.getIntegral() %></ td >
< td ><%= topic.getGrade() %></ td >
</ tr >
<% } %>
<%!
// 截取字符串方法
public String subStr(String str){
if (str == null || "" .equals(str)){
return "" ;
}
if (str.length() > 8 ){
return str.substring( 0 , 8 ) + " " ;
} else {
return str;
}
}
%>
</ table >
</ form >
</ body >
</ html >