Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.
The set tag assigns a value to a variable in a specified scope. It is useful when you wish to assign a variable to a complex expression and then simply reference that variable each time rather than the complex expression. This is useful in both cases: when the complex expression takes time (performance improvement) or is hard to read (code readability improvement).
If the tag is used with body content, the evaluation of the value parameter is omitted. Instead, the String to which the body evaluates is set as value for the scoped variable.
The scopes available are as follows:
application
- the value will be set in application scope according to servlet spec. using the name as its keysession
- the value will be set in session scope according to servlet spec. using the name as keyrequest
- the value will be set in request scope according to servlet spec. using the name as keypage
- the value will be set in page scope according to servlet spec. using the name as keyaction
- the value will be set in the request scope and Struts' action context using the name as keyNOTE: If no scope is specified, it will default to
action
scope.
{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/site/resources/tags/set-description.html %}
{% remote_file_content https://raw.githubusercontent.com/apache/struts/master/core/src/site/resources/tags/set-attributes.html %}
<s:set var="personName" value="person.name"/> Hello, <s:property value="#personName"/> <s:set var="janesName">Jane Doe</s:set> <s:property value="#janesName"/>