jsp中list遍历的内容想实现分页查看,代码怎么写

jsp中list遍历的内容想实现分页查看,代码怎么写,第1张

你的意思是把查询的结果全部保存在list中,然后实现分页?不是吧?数据小还可以,如果有10000条数据,就要存储10000空间。

不过实现的方法是:用jstl标签库的<c:forEach>标签,里面不是有个start和end属性么,动态的改变start和end数值就OK了

jsp页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@page import="javautil,systemVO,systemDAO,systemUtil"%>

<%

Utils user=null;

if(requestgetSession()getAttribute("user")!=null){

user=(Utils)requestgetSession()getAttribute("user");

}

requestsetCharacterEncoding("UTF-8");

responsesetContentType("text/html;charset=UTF-8");

WishPagin wpagin = new WishPagin();

String sql = "select from wishes order by wish_time desc;";

Systemoutprintln(sql);

wpaginsetSql(sql);

ArrayList<Wish> wishes = wpagingetWishes(request

getParameter("page"));

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 401 Transitional//EN" ">

private void indexListBind()

{

try

{

string parID = RequestQueryString["id"]ToString();

int curPage = ConvertToInt32(thislb_pageIndexText) - 1;//获取当前页码,我用的是一个lable当了中间变量

con = Admin_DBgetConn();

conOpen();

DataSet ds = new DataSet();

string Path = "~";

OleDbDataAdapter sda = new OleDbDataAdapter("select ID,'" + Path + "'+imagePath as imagePath,introduce from D_Picture where parID=@parID", con);

sdaSelectCommandParametersAdd(new OleDbParameter("@parID", parID));

sdaFill(ds, "index");

SystemWebUIWebControlsPagedDataSource ps = new PagedDataSource();//实例化分页数据源

psDataSource = dsTables["index"]DefaultView;//将要绑定在datalist上的datatable给分页数据源

psAllowPaging = true;

psPageSize = 8;//每页显示几条记录

psCurrentPageIndex = curPage;//设置当前页的索引(当前页码减1就是)

thisbtn_upEnabled = true;

thisbtn_nextEnabled = true;

thisbtn_fristEnabled = true;

thisbtn_endEnabled = true;

endPage = psPageCount;

if (curPage == 0)//当是第一页是上一页和首页的按钮不可用

{

thisbtn_upEnabled = false;

thisbtn_fristEnabled = false;

}

if (curPage == psPageCount - 1)//当是最后一页时下一页和最后一页的按钮不可用

{

thisbtn_nextEnabled = false;

thisbtn_endEnabled = false;

}

thisindexListDataSource = ps;

thisindexListDataKeyField = "ID";

thisindexListDataBind();

conClose();

}

catch (Exception ex)

{

ConsoleWriteLine(exMessage);

}

}

protected void btn_frist_Click(object sender, EventArgs e)

{

thislb_pageIndexText = "1";

thisindexListBind();

}

protected void btn_up_Click(object sender, EventArgs e)

{

int page = intParse(thislb_pageIndexText) - 1;

thislb_pageIndexText = pageToString();

thisindexListBind();

}

protected void btn_next_Click(object sender, EventArgs e)

{

int page = intParse(thislb_pageIndexText) + 1;

thislb_pageIndexText = pageToString();

thisindexListBind();

}

protected void btn_end_Click(object sender, EventArgs e)

{

thislb_pageIndexText = endPageToString();

thisindexListBind();

}

/给入参数 当前页 和每页显示的记录数 可以返回 想要的集合/

public Collection getBooks(int page, int n) {

Connection conn = null;

Statement stmt = null;

ResultSet rs = null;

int sumRs;

int sumPage;

int currRs;

ArrayList<Bean> booklist = new ArrayList<Bean>();

try {

conn = getConnection();

stmt = conncreateStatement(ResultSetTYPE_SCROLL_INSENSITIVE,

ResultSetCONCUR_READ_ONLY);

rs = stmtexecuteQuery("select from 你的表");

rslast();

sumRs = rsgetRow();

sumPage = (sumRs % n) == 0 (sumRs / n) : (sumRs / n + 1);

currRs = (page - 1) n + 1;

rsabsolute(currRs);

for (int i = 1; i <= n; i++) {

Bean book = new Bean(rsgetInt(1), rsgetString(2), rs

getString(3), rsgetString(4), rsgetString(5), rs

getFloat(6), rsgetInt(7), rsgetString(8), rs

getString(9));

booklistadd(book);

rsnext();

}

} catch (SQLException e) {

// TODO Auto-generated catch block

eprintStackTrace();

} finally {

closeResultSet(rs);

closeStatement(stmt);

closeConnection(conn);

}

return booklist;

}

以上就是关于jsp中list遍历的内容想实现分页查看,代码怎么写全部的内容,包括:jsp中list遍历的内容想实现分页查看,代码怎么写、JSP页面 List 分页,高分跪求。。。本人程序如下:、DataList分页等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9716345.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存