要在action中添加
JSP界面
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>