aspose file tools*
The moose likes Struts and the fly likes how to access this variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to access this variable" Watch "how to access this variable" New topic
Author

how to access this variable

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 370
I defined a variable (I know it is not a very good practice, but let's say I need to).
<% String var = ..... %>

<s:if test="var.startsWith('xyz')=='true'">
...
</s:if>

It seems I can not access this var in the <s:if> tag. What syntax did I use wrong ?

Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

OGNL expressions look on the value stack. Scriptlet variables are not on the value stack. The *easiest* thing to do would be to put the scriptlet variable into a JEE scope (page or request, probably): OGNL expressions *can* access scoped variables.

Really, though, this is a Bad Idea, and there's almost *never* an absolute need to do this.
 
 
subject: how to access this variable
 
Similar Threads
S:elseif not working correctly
Struts 2.0 migration logic:present tag
Struts 2 iterator
Struts 2 Iterate a List of Objects
[Struts 2] Use a JSP variable in struts2 tag