19 Display tag library 1.2

DisplayTag:用于显示表格的标签组件。

displayTag主页:http://displaytag.sourceforge.net/1.2/

下载后找到需要的jar和tld,1.2版本。
displaytag-1.2.jar 放到lib
displaytag.tld放到WEB-INF
web.xml tomcat7.0中
<jsp-config>

<taglib>
<taglib-uri>displaytag </taglib-uri>
<taglib-location>/WEB-INF/displaytag.tld</taglib-location>
</taglib>

</jsp-config>
<filter>
<filter-name>exportFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>
注意:此处的displaytag值和jsp页面中引用的<%@ taglib uri="displaytag " prefix="display"%>中的displaytag要保持一致。

下面四个包从structs2中拷来的也需要加到lib中,也可以到如下地址下载。
commons-lang-2.3.jar http://jakarta.apache.org/commons/lang
commons-collections-3.1.jar http://jakarta.apache.org/commons/collections
commons-beanutils-1.7.0.jar http://jakarta.apache.org/commons/beanutils
commons-logging-1.0.4.jar http://jakarta.apache.org/commons/logging

以上所需要的五个jar和一个tld和一个javabean都在附件中了。

 

jsp例子注意引入java.util.List


注意

tomcat7与tomcat6比较,在web.xml下引入taglib标签的方式有了新的配置要求。

tomcat7.0之前的版本web.xml中taglib配置如下:

<web-app> <taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt_rt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib></web-app>

tomcat7.0后版本taglib配置如下:

<web-app><jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt_rt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>
</jsp-config>

 

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib uri="displaytag" prefix="display"%>
<%@ page import="java.sql.*"%> 
<%@ page import="java.util.*"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>displayTag</title>
<link href="css/displaytag.css" rel="stylesheet" type="text/css"> 
</head>
<body> 
  <%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");      
String connectionUrl = "jdbc:sqlserver://localhost:1088;databaseName=dataBase;user=sa;password=sa;";   
Connection conn = DriverManager.getConnection(connectionUrl);         
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from dataTableName"; 
ResultSet rs=stmt.executeQuery(sql); 

java.util.List list=new ArrayList();           
ResultSetMetaData rsmd = rs.getMetaData();
while ( rs.next() )
{
	Map map = new HashMap();
	
	for ( int i = 1; i <= rsmd.getColumnCount(); i++ )
	{
		map.put(rsmd.getColumnName(i), rs.getObject(i));
	}
	
	list.add(map);
} 

request.setAttribute("results", list);
  %> 
<display:table name="results" class="tagtable" pagesize="2">
	<display:column value="<img src='../images/pic_01.gif'>" style=" width:22px"/>
	<display:column property="id" />
    <display:column property="title" href="newsDetail.jsp" paramId="id" paramProperty="id" />
    <display:column property="content" />
    
    <display:setProperty name="paging.banner.items_name" value="新闻" />
    <display:setProperty name="paging.banner.placement" value="bottom" />
    
    <display:setProperty name="paging.banner.all_items_found">
    <p align=center class="pagebanner">共{0}条{2}</p>
    </display:setProperty>
    
    <display:setProperty name="paging.banner.some_items_found">
    <p align=center class="pagebanner">共{0}条{1}, 本页显示第{2}到第{3}条{1}</p>
    </display:setProperty>
    
    <display:setProperty name="paging.banner.first">
        <div align=center class="pagelinks">
        [<a href="{1}">首页</a>/<a href="{2}">上一页</a>]
        {0}
        [<a href="{3}">下一页</a>/<a href="{4}">尾页</a>]
        </div>
    </display:setProperty>
    
    <display:setProperty name="paging.banner.full">
        <div align=center class="pagelinks">
        [<a href="{1}">首页</a>/<a href="{2}">上一页</a>]
        {0}
        [<a href="{3}">下一页</a>/<a href="{4}">尾页</a>]
        </div>
    </display:setProperty>
    
    <display:setProperty name="paging.banner.last">
        <div align=center class="pagelinks">
        [<a href="{1}">首页</a>/<a href="{2}">上一页</a>]
        {0}
        [<a href="{3}">下一页</a>/<a href="{4}">尾页</a>]
        </div>
    </display:setProperty>
</display:table>
</body>
</html>

 

你可能感兴趣的:(display)