struts2 标签有些属性不能是动态的?

悬赏:10 发布时间:2008-07-11 提问人:lllove (初级程序员)

比如 url 标签的 anchor 属性,只能是静态的字符串。在网上找到同样的问题,但是没有答案:

Hello,

I have the following in my JSP Page:
<a href='<s:url action="myAction" anchor="%{name}" />'>

It seems that the anchor attribute is not evaluating the OGNL.
I guess it's the same problem like this one:
https://issues.apache.org/struts/browse/WW-2015

or is there any reason for not evaluating OGNL ?

Thanks,
Volker

另外,我尝试用scriptlet 来代替
<%
Page myPage = (Page)request.getAttribute("page");
%>
<a href='<s:url action="myAction" anchor="<%=myPage.getAnchor()%>" />'>

错误:
org.apache.jasper.JasperException: /pages/page.jsp(9,1) According to TLD or attribute directive in tag file, attribute anchor does not accept any expressions

采纳的答案

2008-07-25 aidiyuxin (高级程序员)

你可以改下struts2标签的tld
你把
引用
<tag>
<name>url</name>
<attribute>
<name>anchor</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>


<rtexprvalue>false</rtexprvalue>

改成true就可以传动态参数了

提问者对于答案的评价:
我已经用其它方法解决了,谢谢