jsp数字分页谁能给提供一个
[<<][<][1][2][3][4][5][6][7][8][9][10][>][>>]这个样子的jsp分页1...
[<<][<][1] [2] [3] [4] [5] [6] [7] [8] [9] [10][>][>>]
这个样子的jsp分页
1 展开
这个样子的jsp分页
1 展开
3个回答
展开全部
package pageinfo;
import java.util.HashMap;
import java.util.ArrayList;
import java.sql.*;
public class Page {
public int currentpage;
public String parameter;
public int totalrows;
public int pagesize;
public int totalpages;
public String url;
public int getCurrentPage() {
return this.currentpage;
}
public void setCurrentPage(String Tcurrentpage) {
if (Tcurrentpage == null || Tcurrentpage == "") {
this.currentpage = 1;
} else {
this.currentpage = Integer.parseInt(Tcurrentpage);
}
}
public String getParameter() {
return this.parameter;
}
public void setParameter2(String parameter) {
this.parameter = parameter;
}
public int getTotalrows() {
return this.totalrows;
}
public void setTotalrows(int totalrows) {
this.totalrows = totalrows;
}
public int getPageSize() {
return this.pagesize;
}
public void setPageSize(int pagesize) {
this.pagesize = pagesize;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return this.url;
}
public int getTotalPage() {
return (int) Math.ceil((float) totalrows / (float) pagesize);
}
public ArrayList getResult(ResultSet rs) {
ArrayList result = new ArrayList();
int i = 1;
try {
if(rs.getRow() != 0){
ResultSetMetaData rsmd = rs.getMetaData();
rs.absolute((currentpage - 1) * pagesize + 1);
while (i <= pagesize && !rs.isAfterLast()) {
HashMap hashmap = new HashMap();
for (int j = 1; j <= rsmd.getColumnCount(); j++) {
hashmap.put(rsmd.getColumnName(j), rs.getObject(j));
}
result.add(hashmap);
if (!rs.next()) // 当到达最后一个记录时,退出循环
return result;
i++;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
/*
* 使用 for ( int i = 0; i < list.size(); i++ ) { java.util.Map map =
* (java.util.Map)list.get(i);
* out.println(mag.get("column_name").toString()); }
*/
}
public String getHTML() {
StringBuffer pageInfo = new StringBuffer();
/*
* pageInfo.append("第" + currentpage + "页 共" + getTotalPage() + "页, 共" +
* totalrows + "条记录 "); if (currentpage > 1) // 在当前页大于1时有向前翻页的连接,否则没有
* //pageInfo.append("<a href='mainList.jsp?page=" + (currentpage - 1)+
* "'><< 上一页</a>"); pageInfo.append("<a href="+this.url+"?page=" +
* (currentpage - 1)+ "><< 上一页</a>"); else
* pageInfo.append("<< 上一页"); if (currentpage < getTotalPage()) //
* 在当前页小于总页数时有向前翻页的连接,否则没有 pageInfo.append(" <a href="+this.url+"?page=" +
* (currentpage + 1) + ">下一页 >></a>"); else pageInfo.append("下一页
* >>");
*/
pageInfo.append("第" + currentpage + "页 共" + getTotalPage() + "页 共"
+ totalrows + "条记录 ");
pageInfo.append("<a href=" + this.getUrl()
+ "?page=1><< 首页</a>");
if (currentpage > 1) // 在当前页大于1时有向前翻页的连接,否则没有
pageInfo.append("<a href='" + this.getUrl() + "?page="
+ (currentpage - 1) + "'> 上一页</a>");
else
pageInfo.append("上一页");
if (currentpage < getTotalPage()) // 在当前页小于总页数时有向前翻页的连接,否则没有
pageInfo.append(" <a href='" + this.getUrl() + "?page="
+ (currentpage + 1) + "'> 下一页</a>");
else
pageInfo.append(" 下一页 ");
pageInfo.append("<a href='" + this.getUrl() + "?page="
+ (getTotalPage()) + "'> 尾页 >></a>");
return pageInfo.toString();
}
}
jsp页面*************************************
<%
PoolConnection con = new PoolConnection();
Connection conn = con.getConnection();
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
int aguserId = Integer.parseInt(session.getAttribute("aguserid")
.toString());
String sql = "select * from domains where aguserid =" + aguserId;
ResultSet rs = stmt.executeQuery(sql);
String paramPage = request.getParameter("page");
mypage.setCurrentPage(paramPage);
try {
rs.last(); //把指针置底
int totalTopic = rs.getRow(); //获得结果数量
mypage.setTotalrows(totalTopic);
mypage.setPageSize(2);
mypage.setUrl("agdomainlist.jsp");
} catch (Exception e) {
e.printStackTrace();
}
%>
***********************
获得分页
<%=mypage.getHTML()%>
import java.util.HashMap;
import java.util.ArrayList;
import java.sql.*;
public class Page {
public int currentpage;
public String parameter;
public int totalrows;
public int pagesize;
public int totalpages;
public String url;
public int getCurrentPage() {
return this.currentpage;
}
public void setCurrentPage(String Tcurrentpage) {
if (Tcurrentpage == null || Tcurrentpage == "") {
this.currentpage = 1;
} else {
this.currentpage = Integer.parseInt(Tcurrentpage);
}
}
public String getParameter() {
return this.parameter;
}
public void setParameter2(String parameter) {
this.parameter = parameter;
}
public int getTotalrows() {
return this.totalrows;
}
public void setTotalrows(int totalrows) {
this.totalrows = totalrows;
}
public int getPageSize() {
return this.pagesize;
}
public void setPageSize(int pagesize) {
this.pagesize = pagesize;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return this.url;
}
public int getTotalPage() {
return (int) Math.ceil((float) totalrows / (float) pagesize);
}
public ArrayList getResult(ResultSet rs) {
ArrayList result = new ArrayList();
int i = 1;
try {
if(rs.getRow() != 0){
ResultSetMetaData rsmd = rs.getMetaData();
rs.absolute((currentpage - 1) * pagesize + 1);
while (i <= pagesize && !rs.isAfterLast()) {
HashMap hashmap = new HashMap();
for (int j = 1; j <= rsmd.getColumnCount(); j++) {
hashmap.put(rsmd.getColumnName(j), rs.getObject(j));
}
result.add(hashmap);
if (!rs.next()) // 当到达最后一个记录时,退出循环
return result;
i++;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
/*
* 使用 for ( int i = 0; i < list.size(); i++ ) { java.util.Map map =
* (java.util.Map)list.get(i);
* out.println(mag.get("column_name").toString()); }
*/
}
public String getHTML() {
StringBuffer pageInfo = new StringBuffer();
/*
* pageInfo.append("第" + currentpage + "页 共" + getTotalPage() + "页, 共" +
* totalrows + "条记录 "); if (currentpage > 1) // 在当前页大于1时有向前翻页的连接,否则没有
* //pageInfo.append("<a href='mainList.jsp?page=" + (currentpage - 1)+
* "'><< 上一页</a>"); pageInfo.append("<a href="+this.url+"?page=" +
* (currentpage - 1)+ "><< 上一页</a>"); else
* pageInfo.append("<< 上一页"); if (currentpage < getTotalPage()) //
* 在当前页小于总页数时有向前翻页的连接,否则没有 pageInfo.append(" <a href="+this.url+"?page=" +
* (currentpage + 1) + ">下一页 >></a>"); else pageInfo.append("下一页
* >>");
*/
pageInfo.append("第" + currentpage + "页 共" + getTotalPage() + "页 共"
+ totalrows + "条记录 ");
pageInfo.append("<a href=" + this.getUrl()
+ "?page=1><< 首页</a>");
if (currentpage > 1) // 在当前页大于1时有向前翻页的连接,否则没有
pageInfo.append("<a href='" + this.getUrl() + "?page="
+ (currentpage - 1) + "'> 上一页</a>");
else
pageInfo.append("上一页");
if (currentpage < getTotalPage()) // 在当前页小于总页数时有向前翻页的连接,否则没有
pageInfo.append(" <a href='" + this.getUrl() + "?page="
+ (currentpage + 1) + "'> 下一页</a>");
else
pageInfo.append(" 下一页 ");
pageInfo.append("<a href='" + this.getUrl() + "?page="
+ (getTotalPage()) + "'> 尾页 >></a>");
return pageInfo.toString();
}
}
jsp页面*************************************
<%
PoolConnection con = new PoolConnection();
Connection conn = con.getConnection();
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
int aguserId = Integer.parseInt(session.getAttribute("aguserid")
.toString());
String sql = "select * from domains where aguserid =" + aguserId;
ResultSet rs = stmt.executeQuery(sql);
String paramPage = request.getParameter("page");
mypage.setCurrentPage(paramPage);
try {
rs.last(); //把指针置底
int totalTopic = rs.getRow(); //获得结果数量
mypage.setTotalrows(totalTopic);
mypage.setPageSize(2);
mypage.setUrl("agdomainlist.jsp");
} catch (Exception e) {
e.printStackTrace();
}
%>
***********************
获得分页
<%=mypage.getHTML()%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询