JSP标签分页实现(4)
</jsp-config>
我们再编写一个测试用的Servlet:
[java]
public class PagerServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
int curPage = Integer.parseInt(req.getParameter("page") == null ? "1"
: req.getParameter("page"));
List list = new ArrayList();
int start = (curPage -1)* 10 + 1;
int end = start + 10 > 26 ? 26 : start + 10;
for(int i = start; i < end; i++){
list.add(i);
}
PageBean pageBean = new PageBean(25, curPage, list);
req.setAttribute("pb", pageBean);
RequestDispatcher rd = req.getRequestDispatcher("index.jsp");
rd.forward(req,resp);
}
}
这样我们就可以在我们的JSP页面中使用我们自己的标签来完成分页条的显示了。
[html]
<%@ page language="java" import="java.util.*,com.luojing.pager.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="luo" uri="/luo_pager" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>pager test</title>
</head>
<body>
<%
PageBean p = (PageBean) request.getAttribute("pb");
List<Integer> list = p.getItems();
for(Integer i : list){
pageContext.getOut().write("值为: " + i + "<br/>");
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>