1. 找到display tag 所需jar

    display tag 标签分页实例_第1张图片

  2. 编写实体类UserInfo.java

package com.liu.po;
public class UserInfo {
    private Integer userId;
    
    private String userName;
    
    private String userSex;
    public Integer getUserId() {
        return userId;
    }
    public void setUserId(Integer userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getUserSex() {
        return userSex;
    }
    public void setUserSex(String userSex) {
        this.userSex = userSex;
    }
    public UserInfo(Integer userId, String userName, String userSex) {
    
        this.userId = userId;
        this.userName = userName;
        this.userSex = userSex;
    }
    
    
}

3.编写UserServlet.java

package com.liu.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liu.po.UserInfo;
/**
 * Servlet implementation class UserServlet
 */
@WebServlet("/userlist")
public class UserServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List list = new ArrayList();
        for (int i = 0; i < 1000; i++) {
            UserInfo user = new UserInfo(i, "小三" + i, "女");
            list.add(user);
        }
        request.setAttribute("list", list);
        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }
}


4.编写index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>    
<%@ taglib prefix="d" uri="http://displaytag.sf.net" %>



">

Insert title here




    
    查询
    
        
        
        
    
    

5.添加汉化资源文件displaytag.properties,必须放在src目录下

basic.empty.showtable=true
basic.show.header=true
# page | list
sort.amount=list
export.amount=list
export.decorated=true
paging.banner.group_size=8
paging.banner.placement=bottom
css.tr.even=even
css.tr.odd=odd
css.th.sorted=sorted
css.th.ascending=order1
css.th.descending=order2
css.table=
css.th.sortable=sortable
# factory classes for extensions
factory.requestHelper=org.displaytag.util.DefaultRequestHelperFactory
# factory class for decorators
factory.decorator=org.displaytag.decorator.DefaultDecoratorFactory
# locale provider (Jstl provider by default)
locale.provider=org.displaytag.localization.I18nJstlAdapter
# locale.resolver (nothing by default, simply use locale from request)
#locale.resolver=
export.types=csv excel xml pdf
export.csv.class=org.displaytag.export.CsvView
export.excel.class=org.displaytag.export.ExcelView
export.xml.class=org.displaytag.export.XmlView
export.pdf.class=org.displaytag.export.PdfView
export.csv=false
export.csv.label=CSV 
export.csv.include_header=false
export.csv.filename=
export.excel=true
export.excel.label=Excel 
export.excel.include_header=true
export.excel.filename=
export.xml=false
export.xml.label=XML 
export.xml.filename=
export.pdf=false
export.pdf.label=PDF 
export.pdf.include_header=true
export.pdf.filename=
export.rtf=false
export.rtf.label=RTF 
export.rtf.include_header=true
export.rtf.filename=
# messages
basic.msg.empty_list=\u6ca1\u6709\u53ef\u4ee5\u663e\u793a\u7684\u6570\u636e.
basic.msg.empty_list_row=\u6ca1\u6709\u53ef\u4ee5\u663e\u793a\u7684\u6570\u636e.
error.msg.invalid_page=\u975e\u6cd5\u9875\u9762
export.banner=\u8f93\u51fa\u683c\u5f0f: {0}