display tag的简单用法

这是我自己运用display tag写的例子,看了网上写了好多的用法,可是有好多都没有怎么能够运用好,下面是我自己试验的,我自己能够运行的例子。供大家参考:

 

1.首先导入包:displaytag-1.2.jar,commons-lang.jar和standard.jar;

 

2.在web.xml中添加如下的配置:

<!-- display-tag -->
    <filter>
        <filter-name>exportFilter</filter-name>
        <filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>exportFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>

由于我是用到了action所以才过滤了所有的.do的请求

 

3.然后在Action中把取出来的对象放到一个list中,在session.setAttribute("list", list);至于这里用session是为了在后面的页面上面能够分页用的,

list的写法如:List<QuestionType> list = new List<QuestionType>();然后list里面全部放QuestionType的对象。

 

4.首先在JSP页面中引入标签<%@ taglib uri="http://displaytag.sf.net/el" prefix="display"%>;

然后在<head></head>间加入下面的代码,用来显示格式的:

    <style type="text/css">
.table {
 border: 1px solid #74B3DC;
 color: #000;
 background: #fff;
 width: 99% !important;
 width: 99%;
}

.table td,.table th{
 border: 1px solid #e0e0e0;
 border-left: 0px;
 border-top: 0px;
 padding: 0.2em;
 text-align: center;
}
.table thead th{
 border: 1px solid #e0e0e0;
 border-left: 0px;
 border-top: 0px;
 text-align: center;
 font-size: 1em;
 font-weight: bold;
 background: #d7e9f5;
}
}
</style>

 

然后在body中加上如下代码:

<display:table name="sessionScope.lists"  cellspacing="0"
            cellpadding="0" class="table" pagesize="2">
            <display:column property="id" title="编号"/>
            <display:column property="typename" title="类型名称"/>
            <display:column property="typedescribe" title="类型描述"/>
            <display:column property="postDate" title="发表日期"/>
            <display:column property="score" title="答对得分数" />
            <display:column property="deduction" title="答错扣分数"/>
            <display:column property="modify" title="操作" href="controlTypes.do?method=modify" paramId="id" paramProperty="id"></display:column>
            <display:column property="del" title="操作" href="controlTypes.do?method=del" paramId="id" paramProperty="id"></display:column>
        </display:table>

 

5.至于自定义链接的问题我用的是我自己的办法,也实现了功能,我的QuestionType的类是这么写的:

import java.util.Date;

import org.apache.struts.action.ActionForm;

public class QuestionType extends ActionForm {

    private int id;
    private String typename;
    private String typedescribe;
    private Date postDate;
    private int score;
    private int deduction;
    private String modify = "修改";
    private String del = "删除";

    省略了set,get方法
}
在上述的这两行代码: <display:column property="modify" title="操作" href="controlTypes.do?method=modify" paramId="id" paramProperty="id"></display:column>
            <display:column property="del" title="操作" href="controlTypes.do?method=del" paramId="id" paramProperty="id"></display:column>

就是我写的modify和del属性来定义自己的链接的,

 

好了,就这么多了,一点简单的功能希望对大家有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值