Pages Navigation Menu

Coding is much easier than you think

Difference between # , $ and % signs in Struts2

Difference between # , $ and % signs in Struts2

Use of #
OGNL is used to refer to objects in the ActionContext as follows:

  • myObject: object in the ValueStack, such as an Action property
  • #myObject: object in the ActionContext but outside of the ValueStack…
    • #myObject: ActionContext object that has been created using the Struts2 data tags with the default action scope (e.g., <s:set name=”data” value=”Some data” />, referenced by<s:property value=”#data” />)
    • #parameters.myObject: request parameter
    • #request.myObject: request-scoped attribute
    • #session.myObject: session-scoped attribute
    • #application.myObject: application-scoped attribute
    • #attr.myObject: attribute in page, request, session, or application scope, searched in that order.

** UPDATE: Struts 2 Complete tutorial now available here.
The scoped map references above (parameters, request, session, and application) can be made one of two ways:

1. #scopeName['myObject']
2. #scopeName.myObject


Use of $

Struts2 OGNL does not make use of the dollar sign. However, it can be used to evaluate JSTL expressions. For example:

Struts2: <s:property value="someProperty" />
(is equivalent to)
JSTL: ${someProperty}


Use of %

% character is used to force OGNL evaluation of an attribute that would normally interpreted as a String literal. For eample,

<s:url id="urlAtt" action="urlTag.action">
<s:a href="%{urlAtt}">Call Action</s:a>

Now <s:a> tag will query the stack for urlAtt value.


About Mohaideen Jamil

Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

  • Jason

    The beneficiaryExistFlg will either be ‘Y’ or ‘N'; my collection has ‘N’ for first record and ‘Y’ for the second but the s:if test is not working. Please tell me why.

  • suresh

    Hi Jamil,
    I am having two issues.first, while performing edit operation, i am fetching all datas from databse and setting into the request. now how to assign those values to the textfield.?
    second, After saving the datas into the datatabase the values still remains in the to make the value as empty.I know struts follows statefull protocol. How to overcome it. Ex textfield below,

  • suresh

    Hi, I am not getting where to use #,% and and all. please help me to understand this.

    • Mohaideen Jamil

      Hi, the data stored in valuestack (an memory region in ActionContext)can be accessed directly. And any data stored in actionContext but not in ValueStack like attributes, session, request etc can be accessed via #, and % character is used to force OGNL evaluation of an attribute that would normally interpreted as a String literal.