Search code examples
javajspstruts2jstlognl

Setting a variable from object value and using it as a variable elsewhere


I need to prepare a body text in JSTL/OGNL. Something like this:

First Name: <customer.fn>
Last Name: <customer.ln>
...

and use this in the mailto link. Customer comes from the ActionContext.

I tried the following:

<s:set var="bodyText" value="First Name: ${customer.fn}\n Last Name: ${customer.ln}....">

and I tried to print it like this, to see if its working.

<s:property value="#bodyText" />

But this does not seem to work.

Once I get the value, I need to use it in Mailto link like:

"mailto:xyz@abc.com?body=<s:property value="#bodyText">"

Solution

  • You can't use JSP EL in struts tag attribute, but you can use it in the tag body

    <s:set var="bodyText">First Name: ${customer.fn}<br/> Last Name: ${customer.ln}</s:set>