DisplayTag应用实践
2005-03-27 21:21
281 查看
1.表格的显示格式,在css中定义;
2.修改classes/org/displaytag/properties/TableTag.properties,使其符合自己的要求.
详情http://displaytag.sourceforge.net/configuration.html
3.如果TableTag.properties中的相关项包含中文则在web页上会出现乱码,解决方法:下载源码
修改 org.displaytag.properties.TableProperties.java ,把
private String getProperty(String key)
{
return this.properties.getProperty(key);
}
改成
private String getProperty(String key)
{
String s = null;
try {
s = new String(this.properties.getProperty(key).getBytes("8859_1"), "GBK");
}catch(Exception e) {
s = null;
}
return s;
}
4.确保export正确的方法是在web.xml中配置filter:
<filter>
<filter-name>ResponseOverrideFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
详倾参见http://displaytag.sourceforge.net/export.html
慎用这个filter,尤其是使用tomcat做服务器的朋友,它会使本来就存在的乱码问题更加杂乱,除非改改源码.
5.在jstl中获得数据的方法:
<sql:query var="query" dataSource="${bookdev}">
select * from ebook
</sql:query>
<display-el:table name="pageScope.query.rows" />
用<display-el:table name="${query.rows}" />好像不行;
6.要在外部引用数据,必须在display:table中定义一个id
<display-el:table name="pageScope.query.rows" id="item" >
<display-el:column property="title" title="题名" group="1" sortable="true" headerClass="sortable"/>
<display-el:column property="creator" title="作者" group="2" sortable="true" headerClass="sortable"/>
<display-el:column property="format" title="格式"/>
<display-el:column title="删除"><a href="delete.jsp?id=${item.Id}" target="_blank">删除</a></display-el:column>
</display-el:table>
7.问题:如果检索数据库带有中文的字段,在翻页时就查不到记录了?
这个问题着实把我吓了一大条,因为工程马上就要完了,要是它出了问题,那.....
好在displaytag比较成熟,用的人比较多,早就有人提出这个问题了,在网上查了一下,原来又是一个编码的问题:
"DisplayTag的默认的URL默认为上一次的URL,如果上一次的URL包含中文的话,则会被进行URLEncode,所以在翻页的时候,又会把进行了URLEncode后的数据再次进行URLEncode,所以翻页就没有数据,因为这部分功能被封装在DisplayTag中"
也提出了解决办法:在Tomcat的server.xml的Connector部分添加URIEncoding="GBK",
我试了,但是好像不管用,不知道是不是版本不同的缘故,我用的是jakarta-tomcat-5.0.27,应该是比较新的.
考虑到Tomcat5中对Post和Get请求不再采用相同的处理策略,
我把查询表单的form method 由原来的post改为get,翻页就没有问题了,不过这个方法好像蹩脚了点,只能暂时这样了.
在后来的实践中我才发现原来是配置了filter的缘故(见4.确保export正确的方法是在web.xml中配置filter),这个filter打乱了正常的编码.
下面是我的一些测试: (配置了export的filter后)
send.jsp:
<form action="receive.jsp?cs=1" method="POST">
<input name="key" type="text" value="中文" />
<input name="sb" value="submit" type="submit"/>
</form>
receive.jsp:cs=${param.cs};key=${param.key}
结果:cs=1,但key=????即使前面用了<%request.setCharacterEncoding("GBK"); %>也不行
只有用<% String key = new String(request.getParameter("key").getBytes("ISO-8859-1"));out.println(key);%>或类似的编码处理才能得到正确结果.
将send.jsp的form method改为get
结果:cs的值为null,key=中文
8.相关资源:
http://www.theserverside.com/news/thread.tss?thread_id=21861
css
Property | Default | Valid Values | Description | Can be set using file/setProperty |
---|---|---|---|---|
css.tr.even | even | any valid css class name | css class automatically added to even rows | yes/yes |
css.tr.odd | odd | any valid css class name | css class automatically added to odd rows | yes/yes |
css.th.sorted | sorted | any valid css class name | css class automatically added to the header of sorted columns | yes/yes |
css.th.ascending | order1 | any valid css class name | css class automatically added to the header of a column sorted is ascending order | yes/yes |
css.th.descending | order2 | any valid css class name | css class automatically added to the header of a column sorted is descending order | yes/yes |
css.table | none | any valid css class name | css class automatically added to the main table tag | yes/yes |
css.th.sortable | none | any valid css class name | css class automatically added to any sortable column | yes/yes |
Generic
Property | Default | Valid Values | Description | Can be set using file/setProperty |
---|---|---|---|---|
basic.show.header | true | true, false | Indicates if you want the header to appear at the top of the table, the header contains the column names, and any additional action banners that might be required (like paging, export, etc...) | yes/yes |
basic.empty.showtable | false | true, false | Indicates if you want the table to show up also if the list is empty | yes/yes |
basic.msg.empty_list | Nothing found to display | Any string | The message that is displayed if the list that this table is associated with is either null, or empty. Used only if basic.empty.showtableis false. | yes/yes |
basic.msg.empty_list_row | <tr class="empty"><td colspan="{0}">Nothing found to display.</td></tr> | Any string | The message that is displayed into the first table row if the list that this table is associated with is either null, or empty. {0} is replaced with the total column number to generate a correct colspan. Used only if basic.empty.showtableis true. | yes/yes |
sort.amount | page | page, list | Indicates if the full list should be sorted before paging or if the sorting only affects items in the current page. Default behaviour is to sort only items in the current page (first paging, then sorting). | yes/no |
export.banner | <div class="exportlinks"> Export options: {0} </div> | Any string in a message format with 1 placeholder | Contains the string that is displayed in the table footer when the user indicates that they want to enable the export function. The placeholder is replaced with links to the various export formats that are support. | yes/yes |
export.banner.sepchar | | | Any string | Used to separate the valid export type (typically would be a bar, a comma, or a dash). | yes/yes |
paging.banner.placement | top | top, bottom, both | When the table tag has to show the header for paging through a long list, this option indicates where that header should be shown in relation to the table | yes/yes |
paging.banner.item_name | item | Any string | What the various objects in the list being displayed should be referred to as (singular) | yes/yes |
paging.banner.items_name | items | Any string | What the various objects in the list being displayed should be referred to as (plural) | yes/yes |
paging.banner.no_items_found | <span class="pagebanner"> No {0} found. </span> | Any string in a message format with 1 placeholder | What is shown in the pagination header when no objects are available in the list to be displayed. The single placeholder is replaced with the name of the items in the list (plural) | yes/yes |
paging.banner.one_item_found | <span class="pagebanner"> One {0} found. </span> | Any string in a message format with 1 placeholder | What is shown in the pagination header when one object is available in the list to be displayed. The single placeholder is replaced with the name of the items in the list (singular) | yes/yes |
paging.banner.all_items_found | <span class="pagebanner"> {0} {1} found, displaying all {2}. </span> | Any string in a message format with 3 placeholders | What is shown in the pagination header when all the objects in the list are being shown. {0} and {2} are replaced with the number of objects in the list, {1} is replaced with the name of the items {plural} | yes/yes |
paging.banner.some_items_found | <span class="pagebanner"> {0} {1} found, displaying {2} to {3}. </span> | Any string | What is shown in the pagination header when a partial list of the objects in the list are being shown. Parameters: {0}: total number of objects in the list {1}: name of the items (plural) {2}: start index of the objects being shown {3}: end index of the objects being shown {4}: current page {5}: total number of pages | yes/yes |
paging.banner.group_size | 8 | Any reasonable number | The number of pages to show in the header that this person can instantly jump to | yes/yes |
paging.banner.full | <span class="pagelinks"> [<a href="{1}">First</a>/ <a href="{2}">Prev</a>] {0} [ <a href="{3}">Next</a>/ <a href="{4}">Last </a>]</span> | What is shown in the pagination bar when there are more pages and the selected page is not the first or the last one. Parameters: {0}: numbered pages list {1}: link to the first page {2}: link to the previous page {3}: link to the next page {4}: link to the last page {5}: current page {6}: total number of pages | yes/yes | |
paging.banner.first | <span class="pagelinks"> [First/Prev] {0} [ <a href="{3}">Next</a>/ <a href="{4}">Last</a>] </span> | What is shown in the pagination bar when the first page is being shown. Placeholders are the same as for paging.banner.full. | yes/yes | |
paging.banner.last | <span class="pagelinks">[ <a href="{1}">First</a>/ <a href="{2}">Prev</a>] {0} [Next/Last] </span> | What is shown in the pagination bar when the last page is being shown. Placeholders are the same as for paging.banner.full. | yes/yes | |
paging.banner.onepage | <span class="pagelinks">{0}</span> | What is shown in the pagination bar when only one page is returned. Placeholders are the same as for paging.banner.full. | yes/yes | |
paging.banner.page.selected | <strong>{0}</strong> | selected page. {0} is replaced with the page number, {1} with the page url. | yes/yes | |
paging.banner. page.link | <a href="{1}" title="Go to page {0}">{0}</a> | link to a page. {0} is replaced with the page number, {1} with the page url. | yes/yes | |
paging.banner.page.separator | , | separator between pages | yes/yes | |
factory.requestHelper | org.displaytag.util.DefaultRequestHelperFactory | Class name for a valid RequestHelperFactory implementation | RequestHelperFactory to be used. You can replace the default one if you need to generate links with a different format (for example in portal applications). | yes/no |
3.如果TableTag.properties中的相关项包含中文则在web页上会出现乱码,解决方法:下载源码
修改 org.displaytag.properties.TableProperties.java ,把
private String getProperty(String key)
{
return this.properties.getProperty(key);
}
改成
private String getProperty(String key)
{
String s = null;
try {
s = new String(this.properties.getProperty(key).getBytes("8859_1"), "GBK");
}catch(Exception e) {
s = null;
}
return s;
}
4.确保export正确的方法是在web.xml中配置filter:
<filter>
<filter-name>ResponseOverrideFilter</filter-name>
<filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ResponseOverrideFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
详倾参见http://displaytag.sourceforge.net/export.html
慎用这个filter,尤其是使用tomcat做服务器的朋友,它会使本来就存在的乱码问题更加杂乱,除非改改源码.
5.在jstl中获得数据的方法:
<sql:query var="query" dataSource="${bookdev}">
select * from ebook
</sql:query>
<display-el:table name="pageScope.query.rows" />
用<display-el:table name="${query.rows}" />好像不行;
6.要在外部引用数据,必须在display:table中定义一个id
<display-el:table name="pageScope.query.rows" id="item" >
<display-el:column property="title" title="题名" group="1" sortable="true" headerClass="sortable"/>
<display-el:column property="creator" title="作者" group="2" sortable="true" headerClass="sortable"/>
<display-el:column property="format" title="格式"/>
<display-el:column title="删除"><a href="delete.jsp?id=${item.Id}" target="_blank">删除</a></display-el:column>
</display-el:table>
7.问题:如果检索数据库带有中文的字段,在翻页时就查不到记录了?
这个问题着实把我吓了一大条,因为工程马上就要完了,要是它出了问题,那.....
好在displaytag比较成熟,用的人比较多,早就有人提出这个问题了,在网上查了一下,原来又是一个编码的问题:
"DisplayTag的默认的URL默认为上一次的URL,如果上一次的URL包含中文的话,则会被进行URLEncode,所以在翻页的时候,又会把进行了URLEncode后的数据再次进行URLEncode,所以翻页就没有数据,因为这部分功能被封装在DisplayTag中"
也提出了解决办法:在Tomcat的server.xml的Connector部分添加URIEncoding="GBK",
我试了,但是好像不管用,不知道是不是版本不同的缘故,我用的是jakarta-tomcat-5.0.27,应该是比较新的.
考虑到Tomcat5中对Post和Get请求不再采用相同的处理策略,
我把查询表单的form method 由原来的post改为get,翻页就没有问题了,不过这个方法好像蹩脚了点,只能暂时这样了.
在后来的实践中我才发现原来是配置了filter的缘故(见4.确保export正确的方法是在web.xml中配置filter),这个filter打乱了正常的编码.
下面是我的一些测试: (配置了export的filter后)
send.jsp:
<form action="receive.jsp?cs=1" method="POST">
<input name="key" type="text" value="中文" />
<input name="sb" value="submit" type="submit"/>
</form>
receive.jsp:cs=${param.cs};key=${param.key}
结果:cs=1,但key=????即使前面用了<%request.setCharacterEncoding("GBK"); %>也不行
只有用<% String key = new String(request.getParameter("key").getBytes("ISO-8859-1"));out.println(key);%>或类似的编码处理才能得到正确结果.
将send.jsp的form method改为get
结果:cs的值为null,key=中文
8.相关资源:
http://www.theserverside.com/news/thread.tss?thread_id=21861
相关文章推荐
- pip2pi和pypiserver及Apache在pip本地源配置中的应用实践
- 使用内容管理系统做门户网站——JeeCMS应用实践和二次开发
- ASP.NET MVC实践系列2-简单应用
- Java 应用性能调优实践
- IT规划的企业应用实践(1)开 篇 语
- IT规划的企业应用实践(9)研究的目的和意义 之 两大主题
- Hibernate第一课-小应用实践
- IBM InfoSphere DataStage 集群配置管理与应用实践
- Hypertable应用实践:比肩HBase
- 《应用拆分与平台搭建最佳实践》- 拆分中的工作内容
- 解析Monte-Carlo算法(基本原理,理论基础,应用实践)
- iOS应用开发最佳实践:编写高质量的Objective-C代码
- Pinpoint - 应用性能管理(APM)平台实践之部署篇
- Java并发:分布式应用限流 Redis + Lua 实践
- 中小型研发团队架构实践二:如何规范公司所有应用分层
- DotNET企业架构应用实践-系统架构与性能-缓存技术与ORM中的缓存查询技术
- Vuex2.0+Vue2.0构建备忘录应用实践
- HBase在滴滴出行的应用场景和最佳实践
- 3D GIS 应用开发 —— 基于 Mapbox GL 的实践总结
- Docker学习总结(25)——阿里巴巴基于Java容器的多应用部署技术实践