jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to access this variable" Watch "how to access this variable" New topic

how to access this variable

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
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'">

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

David Newton

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: how to access this variable
It's not a secret anymore!