Search code examples
javajspstruts2elognl

Struts2 - JSP EL - Concatenation doesn't seem to work


Trying to figure out this issue for a long time...

I am setting a variable with a value from an Object.

<s:set name="bodyText" value='First Name "myObject.name"'/>

and trying to print it in the following ways.. None of these works.

"${bodyText}"
"<s:property value="#bodyText" />"
"${#bodyText}"
"%{bodyText}"
"%{#bodyText}"

Not sure the problem is with

I tried the following as well:

<s:set name="bodyText" value='First Name "${myObject.name}"'/>

But it did not work.


Solution

  • The value attribute should be an object. OGNL uses quotes to delimit a string object, other quotes should be escaped.

    And use var attribute for variable name.

    <s:set var="bodyText" value="'First Name \"myObject.name\"'"/>
    <s:property value="bodyText" />