struts2中用%{}给自定义标签的属性赋值时 为什么不能返回值
测试了一个自定义标签
自定义标签java文件如下:
public class TestTag extends BodyTagSupport {
private static final long serialVersionUID = 1L;
private String cpage;
private String tpage;
public String getCpage() {
return cpage;
}
public void setCpage(String cpage) {
this.cpage = cpage;
}
public String getTpage() {
return tpage;
}
public void setTpage(String tpage) {
this.tpage = tpage;
}
@Override
public int doEndTag() throws
JspException {
JspWriter out = pageContext.getOut();
try {
String str = "this is tag test!"+ "cpage=" + cpage + "tpage"+ tpage;
out.println(str);
} catch (Exception ex) {
throw new JspTagException("
IOException:" + ex);
}
return super.doEndTag();
}
@Override
public int doStartTag() throws JspException {
return SKIP_BODY;
}
}
标签配制文件
<?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>1.3</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>testTag</short-name>
<uri>http://jakarta.apache.org/struts/tags-bean</uri>
<tag>
<name>test</name>
<tagclass>example.TestTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>cpage</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>tpage</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
测试文件
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="t" uri="/WEB-INF/testTag.tld" %>
<html>
<head>
<title><s:text name="HelloWorld.message"/></title>
</head>
<body>
<h2><s:property value="message"/></h2>
<h3>Languages</h3>
<t:test cpage="%{cpage}" tpage="%{tpage}"/>
<s:property value="%{cpage}"/>
<ul>
<li>
<s:url id="url" action="HelloWorld">
<s:param name="request_locale">en</s:param>
</s:url>
<s:a href="%{url}">English</s:a>
</li>
<li>
<s:url id="url" action="HelloWorld">
<s:param name="request_locale">es</s:param>
</s:url>
<s:a h