Search code examples
struts2strutsognlstruts-tags

Assosiate a request time value to the <s:a> tag in Struts 2


How can I assosiate a request time value to the <s:a> tag in Struts 2?

<% 
  Object myObj= s.get(0);
%>
<s:a cssStyle="something" href="<%=myObj.toString()%>">
   <%=label%>
</s:a>

Solution

  • You don't need to use scriptlets. The same value you can evaluate via OGNL or JSP EL. The value should be set to the action property and have getter for this.

    <s:url var="url" value="%{s[0]}"/>
    <s:a cssStyle="something" href="%{#url}">
       ${label}
    </s:a>