Here is my code:
这是我的代码:
<% request.setAttribute("lcItem", "Hello"); %>
If I do as following, I'm not getting the value:
如果我这样做,我没有得到价值:
<s:property value="%{lcItem}" />
<s:property value="lcItem" />
Any suggestions?
2 个解决方案
#1
This works perfectly..
这完美地工作..
<%
request.setAttribute("lcItem", LeftContentItem);
%>
<s:property value="#request['lcItem']" />
Note: According to the Scope we use we should specify the #request .. etc
注意:根据我们使用的范围,我们应该指定#request ..等
#2
You can write your code 2 ways
您可以通过2种方式编写代码
-
<% request.setAttribute("lcItem", "Hello"); %>
<% pageContext.setAttribute("lcItem", "Hello"); %>
<%request.setAttribute(“lcItem”,“Hello”); %>
<%pageContext.setAttribute(“lcItem”,“Hello”); %>
then if you want to access these values in Struts2 Components you might use #attr. as prefix.
那么如果你想在Struts2组件中访问这些值,你可以使用#attr。作为前缀。
Example
<s:property value="#attr.lcItem">
Note: It will work fine with request and "pageContext".
注意:它可以正常处理请求和“pageContext”。
<s:property value="lcItem" /> will not work because "lcItem" is not available in the Value Stack.
#1
This works perfectly..
这完美地工作..
<%
request.setAttribute("lcItem", LeftContentItem);
%>
<s:property value="#request['lcItem']" />
Note: According to the Scope we use we should specify the #request .. etc
注意:根据我们使用的范围,我们应该指定#request ..等
#2
You can write your code 2 ways
您可以通过2种方式编写代码
-
<% request.setAttribute("lcItem", "Hello"); %>
<% pageContext.setAttribute("lcItem", "Hello"); %>
<%request.setAttribute(“lcItem”,“Hello”); %>
<%pageContext.setAttribute(“lcItem”,“Hello”); %>
then if you want to access these values in Struts2 Components you might use #attr. as prefix.
那么如果你想在Struts2组件中访问这些值,你可以使用#attr。作为前缀。
Example
<s:property value="#attr.lcItem">
Note: It will work fine with request and "pageContext".
注意:它可以正常处理请求和“pageContext”。
<s:property value="lcItem" /> will not work because "lcItem" is not available in the Value Stack.