了解struts2自定义标签的请进
我在WEB-INF目录下创建了tags.tlb内容如下<?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>tags</short-name>
<uri>/tags</uri>
<display-name>"Tangs Tags"</display-name>
<tag>
<name>pages</name>
<tag-class>com.Tag</tag-class> <!-- 指定的JAVA类 -->
<body-content>empty</body-content>
<attribute> <!-- 标签中的属性 -->
<name>th</name> <!-- 属性名 -->
<required>true</required> <!-- 是否必须 -->
<rtexprvalue>true</rtexprvalue> <!-- 表示该自定义标签的某属性的值可以直接指定或者通过动态计算指定 -->
</attribute>
</tag>
</taglib>
然后创建了两个JAVA类分别继承了自定义标签的ComponentTagSupport,Component
第一个是ComponentTagSupport
public Component getBean(ValueStack arg0, HttpServletRequest arg1,
HttpServletResponse arg2) {
System.out.println("getBean");
System.out.println("t:"+th);
return new Tt1(arg0);
}
protected void populateParams() {
super.populateParams();
System.out.println(th);
System.out.println("populateParams");
Tt1 tt = (Tt1)component;
tt.setT1(t1);
tt.setTh(th);
}
第二个是Component
public boolean start(Writer writer) {
boolean result = super.start(writer);
try{
System.out.println("start");
Double d=null;
DecimalFormat df=null;
System.out.println(t1);
System.out.println(th);
if(t1.startsWith("%{")&&t1.endsWith("}")){
System.out.println(t1);
d = new Double(t1);
System.out.println(d.toString());
df=new DecimalFormat( "###,###.## ");
}
System.out.println(df.format(d).toString());
writer.write(df.format(d).toString());
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}
页面代码
"S2:" <s:property value="t1"/><br>
"自定义:" <u:pages th="%{t1 }"/>
action 代码
public String execute() throws Exception{
t1="3331000.00";
System.out.println("dd");
return "input";
}
但是自定义标签不是t1传入后台的参数不是3331000.00而是%{t1} --------------------编程问答-------------------- 没人懂吗??? --------------------编程问答-------------------- 他们提供的都已经够用了,自定义标签没有搞过
补充:Java , Web 开发