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.