If I do the following, I do not ...">

How to get JSP script value in struts tag

Here is my code:

<% request.setAttribute("lcItem", "Hello"); %>

If I do the following, I do not get the value:

<s:property value="%{lcItem}" />
<s:property value="lcItem" />

Any suggestions?

+5
source share
2 answers

This works great.

<%       
   request.setAttribute("lcItem", LeftContentItem);
%>

<s:property value="#request['lcItem']" />

Note. According to the scope, we must specify #request .. etc.

+5
source

You can write your code in two ways

  • <% request.setAttribute("lcItem", "Hello"); %>
  • <% pageContext.setAttribute("lcItem", "Hello"); %>

then if you want to access these values ​​in Struts2 components, you can use #attr. as a prefix.

Example

<s:property value="#attr.lcItem">

Note. It will work fine with the request and the "pageContext".

<s:property value="lcItem" /> will not work because "lcItem" is not available in the Value Stack.
0
source

All Articles