display tag 标签分页实例

  1. 找到display tag 所需jar

    wKiom1ZFQN-DTqZeAAA6Dr0KA0Y362.png

  2. 编写实体类UserInfo.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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<UserInfo> list =  new  ArrayList<UserInfo>();
         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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ 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"  %>
<!DOCTYPE html PUBLIC  "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<base href= "<%=basePath%>" >
<meta http-equiv= "Content-Type"  content= "text/html; charset=UTF-8" >
<title>Insert title here</title>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel= "stylesheet"  href= "//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" >
</head>
<body>
     <div align= "center" >
     <a href= "userlist" >查询</a>
     <d:table name= "list"  class = "table"  pagesize= "10"  export= "true"  requestURI= "userlist" >
         <d:column property= "userId"  title= "编号"  sortable= "true" ></d:column>
         <d:column property= "userName"  title= "姓名" ></d:column>
         <d:column property= "userSex"  title= "性别" ></d:column>
     </d:table>
     </div>
</body>
</html>

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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=<span  class = "export csv" >CSV </span>
export.csv.include_header= false
export.csv.filename=
export.excel= true
export.excel.label=<span  class = "export excel" >Excel </span>
export.excel.include_header= true
export.excel.filename=
export.xml= false
export.xml.label=<span  class = "export xml" >XML </span>
export.xml.filename=
export.pdf= false
export.pdf.label=<span  class = "export pdf" >PDF </span>
export.pdf.include_header= true
export.pdf.filename=
export.rtf= false
export.rtf.label=<span  class = "export rtf" >RTF </span>
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=<tr  class = "empty" ><td colspan= "{0}" >\u6ca1\u6709\u53ef\u4ee5\u663e\u793a\u7684\u6570\u636e.</td></tr>
error.msg.invalid_page=\u975e\u6cd5\u9875\u9762
export.banner=<div  class = "exportlinks" >\u8f93\u51fa\u683c\u5f0f: { 0 }</div>
export.banner.sepchar= |
paging.banner.item_name=
paging.banner.items_name=
paging.banner.no_items_found=<span  class = "pagebanner" >\u6ca1\u6709\u8BB0\u5F55.</span>
paging.banner.one_item_found=<span  class = "pagebanner" >\u603b\u5171\u4e00\u6761\u8bb0\u5f55.</span>
paging.banner.all_items_found=<span  class = "pagebanner" >\u603b\u5171{ 0 }{ 1 }\u6761\u8bb0\u5f55.</span>
paging.banner.some_items_found=<span  class = "pagebanner" >\u603b\u5171{ 0 }{ 1 }\u6761\u6570\u636e</span>
paging.banner.full=<span  class = "pagelinks" ><a href= "{1}" >\u9996\u9875</a>&nbsp;<a href= "{2}" >\u4e0a\u4e00\u9875</a>&nbsp;<a href= "{3}" >\u4e0b\u4e00\u9875</a>&nbsp;<a href= "{4}" >\u5c3e\u9875</a>&nbsp;<select  class = "pagelinks"  name= "page"  onchange= "location=page.value" >{ 0 }</select></span>
paging.banner.first=<span  class = "pagelinks" >\u9996\u9875&nbsp;\u4e0a\u4e00\u9875&nbsp;<a href= "{3}" >\u4e0b\u4e00\u9875</a>&nbsp;<a href= "{4}" >\u5c3e\u9875</a>&nbsp;<select  class = "pagelinks"  name= "page"  onchange= "location=page.value" >{ 0 }</select></span>
paging.banner.last=<span  class = "pagelinks" ><a href= "{1}" >\u9996\u9875</a>&nbsp;<a href= "{2}" >\u4e0a\u4e00\u9875</a>&nbsp;\u4e0b\u4e00\u9875&nbsp;\u5c3e\u9875&nbsp;<select  class = "pagelinks"  name= "page"  onchange= "location=page.value" >{ 0 }</select></span>
paging.banner.onepage=<span  class = "pagelinks" >\u5171\u4e00\u9875</span>
paging.banner.page.selected=<option value= "#"  selected>{ 0 }</option>
#<strong>{ 0 }</strong>
paging.banner.page.link=<option value= "{1}" >{ 0 }</option>
#&nbsp;<input size= '2' >&nbsp;<input type= 'button'  value= 'Go' >
#<a href= "{1}"  title= "Go to page {0}" >{ 0 }</a>
paging.banner.page.separator=
#, \
# external sort and pagination
pagination.sort.param=sort
pagination.sortdirection.param=dir
pagination.pagenumber.param=page
pagination.searchid.param=searchid
pagination.sort.asc.value=asc
pagination.sort.desc.value=desc
pagination.sort.skippagenumber= true
# unused
save.excel.banner=<a href= "{0}"  rel= "external" >save ({ 1 } bytes)</a>
save.excel.filename=export.xls

6.最终效果

wKiom1ZFQdiz-7-4AABHo5PRFik359.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值