You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Westerman <dl...@us.ibm.com> on 2010/11/16 17:04:36 UTC

Setting and Getting Variables

I am having a lot of trouble getting my head around how to access the 
different variables in Struts and JSP, and it's causing me all kinds of 
problems.

All I am trying to do is set a variable in my page from a variable in my 
Action class, in order to use it at various places in my page.

<s:set var="backgroundImage" 
value="'background-image:url(\"%{customImageFileUrl}\");'" />

The result is:
customImageFileUrl = /social/aggregator/sitetemp/site1/i_bg-hdr-sma.jpg
backgroundImage = background-image:url("%{customImageFileUrl}"); 

I've tried '#' instead of '%', and it also takes that as a literal. I've 
tried '$' instead of '%', and also using <s:property>, but both of those 
give me JSP compile errors.

Is there some way to put the value of 'customImageFileUrl' from my action 
class into a variable that I can use in the page?

Thanks!

Re: Setting and Getting Variables

Posted by Maurizio Cucchiara <ma...@gmail.com>.
What about using
<s:set var="backgroundImage"
value="'background-image:url(' + customImageFileUrl + ');'" />

<s:property value="backgroundImage"/>


2010/11/16 Dave Westerman <dl...@us.ibm.com>

> I am having a lot of trouble getting my head around how to access the
> different variables in Struts and JSP, and it's causing me all kinds of
> problems.
>
> All I am trying to do is set a variable in my page from a variable in my
> Action class, in order to use it at various places in my page.
>
> <s:set var="backgroundImage"
> value="'background-image:url(\"%{customImageFileUrl}\");'" />
>
> The result is:
> customImageFileUrl = /social/aggregator/sitetemp/site1/i_bg-hdr-sma.jpg
> backgroundImage = background-image:url("%{customImageFileUrl}");
>
> I've tried '#' instead of '%', and it also takes that as a literal. I've
> tried '$' instead of '%', and also using <s:property>, but both of those
> give me JSP compile errors.
>
> Is there some way to put the value of 'customImageFileUrl' from my action
> class into a variable that I can use in the page?
>
> Thanks!




-- 
Maurizio Cucchiara