jspStruts2的分页处理

要在action中添加
private int nowPage=1;
	
public int getNowPage() {
		return nowPage;
	}



	public void setNowPage(int nowPage) {
		this.nowPage = nowPage;
	}

重数据库中获得数据并保存在request中好在JSP界面中获取

int row=0;
		 QueryUpdate qu=new QueryUpdate();
		 String sql1="select * from news_info";
		 row=qu.getRows(sql1);
	     page=new pageControlor(4,row);
	     
		page.setNowPage(nowPage);
		String sql="select * from news_info limit "+page.getStart()+","+page.getPageSize(); 
		ResultSet rs=qu.query(sql);
		newsList=new ArrayList<News>();
		try {
			while(rs.next()){
		    News news = new News();
			news.setId(rs.getInt(1));
			news.setTitle(rs.getString(2));
			news.setCotent(rs.getString(3));
			news.setAuthor(rs.getString(4));
			news.setHits(rs.getInt(5));
			news.setAdmin_id(rs.getInt(6));
			news.setGroup_id(rs.getInt(7));
			news.setKey(rs.getString(8));
			news.setTime(rs.getString(9));
			news.setNews_image(rs.getString(10));
			newsList.add(news);
			}}
		 catch (SQLException e) {
			e.printStackTrace();
		}
         
		HttpServletRequest request = ServletActionContext.getRequest();
		request.setAttribute("news", newsList);
		request.setAttribute("pageAll",page.getPageAll());
		request.setAttribute("row",page.getAllRows());
		request.setAttribute("last",page.getLast());
		request.setAttribute("pro",page.getPro());
		request.setAttribute("next",page.getNext());
		request.setAttribute("nowPage",page.getNowPage());
		return "success";

JSP界面


 

<tr><td colspan="8" nowrap background=admin_poli.files/th_bg.gif height=25 >
   总页数:<%=request.getAttribute("pageAll") %>  总条数:<%=request.getAttribute("row") %>  第<%=request.getAttribute("nowPage") %>页   
         <a href="queryAllNews.action?nowPage=1">首页</a>    <a href="queryAllNews.action?nowPage=<%=request.getAttribute("pro")%>">上一页</a>   <a href="queryAllNews.action?nowPage=<%=request.getAttribute("next")%>">下一页</a>   <a href="queryAllNews.action?nowPage=<%=request.getAttribute("last")%>">尾页</a>
  </td></tr>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值