您的位置:首页 > 编程语言 > Java开发

Struts 2不再支持在struts tag里使用JSP EL表达式

2008-03-07 22:14 447 查看
当你使用struts 2 tags时,如果使用代码:

<s:set name="name" value="<%= "'" + request.getParameter("name") + "'" %>" />

或者

<s:set name="name" value="${param.name}" />

都会发生下列错误:

According to TLD or attribute directive in tag file, attribute value does not accept any expressions

而得使用:

<s:set name="name" value="#parameters.name[0]" />

才行

原因可能是因为你使用了<%..%>代码 or JSP EL表达式。Struts 2从 version 2.0.11开始已经不支持struts tag与JSP EL表达式混合使用了(不在struts tag里使用EL还是可以的),而只支持OGNL (关于OGNL介绍的中文连接:http://www.blogjava.net/max/archive/2007/04/28/114417.html)。

原因见:http://struts.apache.org/2.0.11/docs/release-notes-2011.html

中文讨论是:http://www.javaeye.com/news/193

相关的讨论有:

http://www.nabble.com/AppFuse-Struts-2-Basic-%2B-Hibernate---upgrade-to-AppFuse-2.0.1--%3E-Struts-Taglib-problem--td14749012s2369.html

http://issues.appfuse.org/browse/APF-941

http://www.nabble.com/Update-from-2.0.9-to-2.0.11-td14594912.html

Trick Tip:

对于<s:property>,是使用

<s:property value="#parameters.name" />

而对于<s:set>,则要使用(否则出错):

<s:set name="name" value="#parameters.name[0]" />

但是如果使用struts include tag来传参数,则<s:property>和<s:set>无法获取传来的参数,如:

<body>
<s:include value= "/welcome.jsp">
<s:param name="name">Scott</s:param>
</s:include>
</body>

那么在webcome.jsp里通过<s:property>和<s:set>无法获取"name"参数:

<s:property value="#parameters.name" />

<s:set name="name" value="#parameters.name[0]" />

而只能够用

<%request.getParameter("name")%>

来获取
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: