在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 一致)显示数据