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

当你使用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

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")%>来获取

转载自:http://blog.csdn.net/hoking_in/article/details/7903712

原文地址:https://www.cnblogs.com/babybluevino/p/2802518.html