我建了tld自定义标签:
<mytag:helloworld str="123"/> 这样可以输出123<% request.setAttribute("attr","456"); %>
<mytag:helloworld str="%{attr}"/>这里本应该输出456,才对,为什么我的输出结果是%{attr}呢下面是我的部分代码:
my.tld
...
<tag>
<name>helloworld</name>
<tag-class>test.MyTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>str</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>MyTag.javapackage test;import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TagSupport;public class MyTag extends TagSupport { private String str = ""; @Override
public int doEndTag() throws JspException {
try {
pageContext.getOut().print(str);
} catch (Exception e) {
}
return SKIP_BODY;
} @Override
public int doStartTag() throws JspException {
return SKIP_BODY;
} public String getStr() {
return str;
} public void setStr(String str) {
this.str = str;
}}

解决方案 »

  1.   

    <mytag:helloworld str="%{attr}"/>不对吧,是不是应该这样写<mytag:helloworld str="<%= request.getAttribute("attr") %>"/>
    没见过像你那样取值的啊!!使用EL表达式也应该是这样${requestScope.attr}吧。
      

  2.   

    <mytag:helloworld str="%{attr}"/>
        这个地方不明白呀:% or $<mytag:helloworld str="hello"/>标签处理类中:
    pageContext.getOut().print(str); 这样就可以输出了吧?