STRUTS2 TAG

在default.properties文件中:

struts.ui.theme=xhtml
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl 

你可以在struts.properties文件覆盖它

struts.ui.theme=simple
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
也可以修改struts.xml文件,结果是一样的
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.ui.templateDir" value="template" />
<constant name="struts.ui.templateSuffix" value="ftl" />

然后写个类extends UIBean,我的类是Graph,实现getDefaultTemplate(),返回自定义的TEMPLATE,如:

public static final String TEMPLATE = "graph";

protected String getDefaultTemplate() {
  return TEMPLATE;
 }

构造函数

public Graph(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
        super(stack, request, response);
    }

实现evaluateParams方法,对标签进行求值

其它就是属性(标签选项)的getter/setter

还要写一个类extends ComponentTagSupport,我的类是GraphTag,实现populateParams和getBean方法,

populateParams方法是接收标签参数值,传给Graph。

getBean比较简单了:

public Component getBean(
   ValueStack stack,
   HttpServletRequest request,
   HttpServletResponse response) {

  return new Graph(stack, request, response);
 }

其它的就是属性(就是Graph属性)的getter/setter.

然后再在/META-INF文件夹下建.tld文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
  <tlib-version>2.2.3</tlib-version>
  <jsp-version>1.2</jsp-version>
  <short-name>m</short-name>
  <uri>/connext</uri>
  <display-name>"Connext Tags"</display-name>
  <description><![CDATA["这里是介绍文字"]]></description>
  <tag>
   <name>head</name>
    <tag-class>你的类路径</tag-class>
    <body-content>JSP</body-content>
    <description><![CDATA[这里是介绍文字]]></description>
  </tag>

</taglib>

在你的jsp页面里声明下

<%@ taglib prefix="m" uri="/connext"%>

<m:head></m:head>

最后是标签样式了,在template/simple文件夹下graph.ftl(要和你开始设置struts.ui.theme=simple
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl    一致)显示数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值