J2EE中使用Display标记库来展示表格
2008-02-23 08:07:35来源:互联网 阅读 ()
数据模型是很简单的美国总统JavaBean.它有3个简单的String属性。
Java代码如下:
PagedData.java
import java.util.ArrayList;
import java.util.List;
public class PagedData {
private List list;
public PagedData( ) {
list = new ArrayList( );
list.add( new President( "Garfield", "James", "1881") );
list.add( new President( "Arthur", "Chester", "1881-85") );
list.add( new President( "Cleveland", "Grover", "1885-89") );
list.add( new President( "Harrison", "Benjamin", "1889-93") );
list.add( new President( "Cleveland", "Grover", "1893-97") );
list.add( new President( "McKinley", "William", "1897-1901") );
list.add( new President( "Roosevelt", "Theodore", "1901-09") );
list.add( new President( "Taft", "William H.", "1909-13") );
list.add( new President( "Wilson", "Woodrow", "1913-21") );
list.add( new President( "Jackson", "Andrew", "1829-37") );
list.add( new President( "Harding", "Warren", "1921-23") );
list.add( new President( "Coolidge", "Calvin", "1923-29") );
list.add( new President( "Hoover", "Herbert", "1929-33") );
list.add( new President( "Roosevelt", "Franklin D.", "1933-45") );
list.add( new President( "Truman", "Harry", "1945-53") );
list.add( new President( "Eisenhower", "Dwight", "1953-61") );
list.add( new President( "Kennedy", "John F.", "1961-63") );
list.add( new President( "Johnson", "Lyndon", "1963-69") );
list.add( new President( "Nixon", "Richard", "1969-74") );
list.add( new President( "Ford", "Gerald", "1974-77") );
list.add( new President( "Carter", "Jimmy", "1977-81") );
list.add( new President( "Reagan", "Ronald", "1981-89") );
list.add( new President( "Bush", "George H.W.", "1989-93") );
list.add( new President( "Clinton", "William J.", "1993-2001") );
list.add( new President( "Bush", "George W.", "2001-present") );
list.add( new President( "Washington", "George", "1789-97") );
list.add( new President( "Adams", "John", "1797-1801") );
list.add( new President( "Jefferson", "Thomas", "1801-09") );
list.add( new President( "Madison", "James", "1809-17") );
list.add( new President( "Monroe", "James", "1817-25") );
list.add( new President( "Jackson", "Andrew", "1829-37") );
list.add( new President( "Van Buren", "Martin", "1837-41") );
list.add( new President( "Harrison", "William Henry", "1841") );
list.add( new President( "Tyler", "John", "1841-45") );
list.add( new President( "Polk", "James", "1845-49") );
list.add( new President( "Taylor", "Zachary", "1849-50") );
list.add( new President( "Fillmore", "Millard", "1850-53") );
list.add( new President( "Pierce", "Franklin", "1853-57") );
list.add( new President( "Buchanan", "James", "1857") );
list.add( new President( "Lincoln", "Abraham", "1861-65") );
list.add( new President( "Johnson", "Andrew", "1865-69") );
list.add( new President( "Grant", "Ulysses S.", "1869-77") );
list.add( new President( "Hayes", "Rutherford B.", "1877-81") );
}
public List getData( ) {
return list;
}
}
President.java
public class President {
public President(String lname, String fname, String term) {
lastName = lname;
firstName = fname;
this.term = term;
}
public String getFirstName( ) {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName( ) {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getTerm( ) {
return term;
}
public void setTerm(String term) {
this.term = term;
}
private String lastName;
private String firstName;
private String term;
}
下面的Jsp页面是展示表格的,也体现了Display库最常见的用法:
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display" %>
<html>
<head>
<title>Struts Cookbook - Chapter 4 : Display Tag Example</title>
<style>
.even {background-color:orange;}
.odd {background-color:yellow;}
</style>
</head>
<body>
<h2>Display Tag Examples</h2>
<jsp:useBean id="pagedData" class="PagedData"/>
<display:table id="pres" name="${pagedData.data}"
sort="list" pagesize="10" defaultsort="3">
<display:caption>United States Presidents</display:caption>
<display:setProperty name="basic.show.header" value="true"/>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash