jsp的翻页功能怎么做啊? 老师要求从数据库中查询一部分数据,可以提供查询几页.如果还想看再下一页的话,再从数据库中查询,又可提供几页工查询.怎么实现啊,有代码的更好.大家帮帮忙!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 分页算法:package demo.gyl;public class PageBean {private int currentPage = 1;// 当前页数public int totalPages = 0;// 总页数private int pageSize = 0;// 每页显示数private int totalRows = 0;// 总数据数private int startNum = 0;// 开始记录private int nextPage = 0;// 下一页private int previousPage = 0;// 上一页private boolean hasNextPage = false;// 是否有下一页private boolean hasPreviousPage = false;// 是否有前一页public PageBean(int pageSize, int currentPage, int totalRows) {this.pageSize = pageSize;this.currentPage = currentPage;this.totalRows = totalRows;if ((totalRows % pageSize) == 0) {totalPages = totalRows / pageSize;} else {totalPages = totalRows / pageSize + 1;}if (currentPage >= totalPages) {hasNextPage = false;currentPage = totalPages;} else {hasNextPage = true;}if (currentPage <= 1) {hasPreviousPage = false;currentPage = 1;} else {hasPreviousPage = true;}startNum = (currentPage - 1) * pageSize;nextPage = currentPage + 1;if (nextPage >= totalPages) {nextPage = totalPages;}previousPage = currentPage - 1;if (previousPage <= 1) {previousPage = 1;}}public boolean isHasNextPage() {return hasNextPage;}public boolean isHasPreviousPage() {return hasPreviousPage;}/*** @return the nextPage*/public int getNextPage() {return nextPage;}/*** @param nextPage* the nextPage to set*/public void setNextPage(int nextPage) {this.nextPage = nextPage;}/*** @return the previousPage*/public int getPreviousPage() {return previousPage;}/*** @param previousPage* the previousPage to set*/public void setPreviousPage(int previousPage) {this.previousPage = previousPage;}/*** @return the currentPage*/public int getCurrentPage() {return currentPage;}/*** @param currentPage* the currentPage to set*/public void setCurrentPage(int currentPage) {this.currentPage = currentPage;}/*** @return the pageSize*/public int getPageSize() {return pageSize;}/*** @param pageSize* the pageSize to set*/public void setPageSize(int pageSize) {this.pageSize = pageSize;}/*** @return the totalPages*/public int getTotalPages() {return totalPages;}/*** @param totalPages* the totalPages to set*/public void setTotalPages(int totalPages) {this.totalPages = totalPages;}/*** @return the totalRows*/public int getTotalRows() {return totalRows;}/*** @param totalRows* the totalRows to set*/public void setTotalRows(int totalRows) {this.totalRows = totalRows;}/*** @param hasNextPage* the hasNextPage to set*/public void setHasNextPage(boolean hasNextPage) {this.hasNextPage = hasNextPage;}/*** @param hasPreviousPage* the hasPreviousPage to set*/public void setHasPreviousPage(boolean hasPreviousPage) {this.hasPreviousPage = hasPreviousPage;}/*** @return the startNum*/public int getStartNum() {return startNum;}/*** @param startNum* the startNum to set*/public void setStartNum(int startNum) {this.startNum = startNum;}}SERVLET或ACTION里面调用这个BEAN,主要是在显示页面,写一个表单并让它指向SERVLET,通过JS来改变当前页(currentPage)的值。从网上COPY的.非原创. //创建一个可以滚动的只读的SQL语句对象 sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.Result Set.CONCUR_READ_ONLY);//什么是一个可以滚动的只读的SQL语句对象啊,它起到什么作用啊?就是先查一部分吗? 结果集的游标可以自由定位,自己把游标的位置随便放置举个例子,你总共有1000条记录每次显示50条,当前页码是2,那么点击“下一页”,记录开始的位置就是rs.at(pageNo*50)。不加前面那段的话,rs.at会报错。 说的前面那段是说java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.Result Set.CONCUR_READ_ONLY这个吗? 这句只是为了在sql server 2005中能正确移动游标写的,在2008之后的就不用加的。 求weblogic 9.2字符集设置 Hibernate+spting+struts+ajax 整合问题 struts 必须用struts的标签吗? 100分,以下是POI读取EXCEL导入DB2数据库的源程序,在JSP中如何调用,完成导入数据库的功能? 毕业设计急用(中文乱码处理) 菜鸟求救:hibernate DAO的问题 關於數據庫連接的問題 制作javabean出错,求解~! 为什么double转换成String类型时总是出错。 hibernate中级联(一对一)? java如何获取网页截图 https下使用的数字证书类型
this.currentPage = currentPage;
this.totalRows = totalRows;if ((totalRows % pageSize) == 0) {
totalPages = totalRows / pageSize;
} else {
totalPages = totalRows / pageSize + 1;
}if (currentPage >= totalPages) {
hasNextPage = false;
currentPage = totalPages;
} else {
hasNextPage = true;
}if (currentPage <= 1) {
hasPreviousPage = false;
currentPage = 1;
} else {
hasPreviousPage = true;
}startNum = (currentPage - 1) * pageSize;nextPage = currentPage + 1;if (nextPage >= totalPages) {
nextPage = totalPages;
}previousPage = currentPage - 1;if (previousPage <= 1) {
previousPage = 1;
}}public boolean isHasNextPage() {return hasNextPage;}public boolean isHasPreviousPage() {return hasPreviousPage;}/**
* @return the nextPage
*/
public int getNextPage() {
return nextPage;
}/**
* @param nextPage
* the nextPage to set
*/
public void setNextPage(int nextPage) {
this.nextPage = nextPage;
}/**
* @return the previousPage
*/
public int getPreviousPage() {
return previousPage;
}/**
* @param previousPage
* the previousPage to set
*/
public void setPreviousPage(int previousPage) {
this.previousPage = previousPage;
}/**
* @return the currentPage
*/
public int getCurrentPage() {
return currentPage;
}/**
* @param currentPage
* the currentPage to set
*/
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}/**
* @return the pageSize
*/
public int getPageSize() {
return pageSize;
}/**
* @param pageSize
* the pageSize to set
*/
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}/**
* @return the totalPages
*/
public int getTotalPages() {
return totalPages;
}/**
* @param totalPages
* the totalPages to set
*/
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}/**
* @return the totalRows
*/
public int getTotalRows() {
return totalRows;
}/**
* @param totalRows
* the totalRows to set
*/
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}/**
* @param hasNextPage
* the hasNextPage to set
*/
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}/**
* @param hasPreviousPage
* the hasPreviousPage to set
*/
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}/**
* @return the startNum
*/
public int getStartNum() {
return startNum;
}/**
* @param startNum
* the startNum to set
*/
public void setStartNum(int startNum) {
this.startNum = startNum;
}
}SERVLET或ACTION里面调用这个BEAN,主要是在显示页面,写一个表单并让它指向SERVLET,通过JS来改变当前页(currentPage)的值。从网上COPY的.非原创.
sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.Result Set.CONCUR_READ_ONLY);//什么是一个可以滚动的只读的SQL语句对象啊,它起到什么作用啊?就是先查一部分吗?
结果集的游标可以自由定位,自己把游标的位置随便放置
举个例子,你总共有1000条记录
每次显示50条,当前页码是2,那么点击“下一页”,记录开始的位置就是rs.at(pageNo*50)。
不加前面那段的话,rs.at会报错。
说的前面那段是说java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.Result Set.CONCUR_READ_ONLY这个吗?