JSP中MVC模式的Demo(2)
<td><%=ub.getName()%></td>
<td><%=ub.getAge()%></td></tr>
<%
}
////从object --> string --int
int pageCount = Integer.parseInt((String)request.getAttribute("pageCount")) ;
//int pageCount = ubd.getPageCount();
for(int i=1;i<pageCount;i++){
%>
<a href=UserDL?pageNow=<%=i%>><<%=i%>></a>
<%
} www.2cto.com
%>
</table>
UserDL.java是个专门用于分页的Servlet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("通过Servlet分页");
String s_pageNow = request.getParameter("pageNow");
UserBeanDL ubd = new UserBeanDL();
try{
int pageNow = Integer.parseInt(s_pageNow);
ArrayList al = ubd.getUsersByPage(pageNow);
int pageCount = ubd.getPageCount();
request.setAttribute("pageNow", pageNow);
request.setAttribute("result", al);
request.setAttribute("pageCount", pageCount + "");
request.getRequestDispatcher("threedown/welcome.jsp").forward(request, response);
}catch(Exception e){
e.printStackTrace();
}
}
摘自 漂泊小七的专栏
相关新闻>>
- 发表评论
-
- 最新评论 更多>>