1.表格的显示格式,在css中定义;
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 |
2.修改classes/org/displaytag/properties/TableTag.properties,使其符合自己的要求.
basic.empty.showtable=false
basic.show.header=true
# page | list
sort.amount=page
export.amount=list
export.decorated=true
paging.banner.group_size=8
paging.banner.placement=top
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
# 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=true
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=true
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=
# messages
basic.msg.empty_list=<center>对不起,没有符合条件的记录</center>
basic.msg.empty_list_row=<tr class="empty"><td colspan="{0}">Nothing found to display.</td></tr>
error.msg.invalid_page=invalid page
export.banner=<div class="exportlinks">Export options: {0}</div>
export.banner.sepchar= |
paging.banner.item_name=记录
paging.banner.items_name=记录
paging.banner.no_items_found=<span class="pagebanner">没有任何{0} .</span>
paging.banner.one_item_found=<span class="pagebanner">搜索到1条{0} .</span>
paging.banner.all_items_found=<span class="pagebanner">搜索到<b>{0}</b>条{1}, 当前显示全部{2}.</span>
paging.banner.some_items_found=<span class="pagebanner">搜索到<b>{0}</b>条{1} , 当前显示<b>{2}</b> to <b>{3}</b>.</span>
paging.banner.full=<span class="pagelinks">[<a href="{1}">首页</a>/<a href="{2}">上一页</a>] {0} [<a href="{3}">下一页</a>/<a href="{4}">末页</a>]</span>
paging.banner.first=<span class="pagelinks">[首页/上一页] {0} [<a href="{3}">下一页</a>/<a href="{4}">末页</a>]</span>
paging.banner.last=<span class="pagelinks">[<a href="{1}">首页</a>/<a href="{2}">上一页</a>] {0} [下一页/末页]</span>
paging.banner.onepage=<span class="pagelinks">{0}</span>
paging.banner.page.selected=<strong>{0}</strong>
paging.banner.page.link=<a href="{1}" title="Go to page {0}">{0}</a>
paging.banner.page.separator=,
# unused
save.excel.banner=<a href="{0}" rel="external">save ({1} bytes)</a>
save.excel.filename=export.xls
详情
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
posted on 2005-06-07 15:46
似水流年 阅读(2252)
评论(0) 编辑 收藏 所属分类:
JSP/Servlet