Apache Struts 2 Documentation > Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > Generic Tag Reference > set |
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 eveluates is set as value for the scoped variable.
The scopes available are as follows :-
NOTE:
If no scope is specified, it will default to action scope.
Dynamic Attributes Allowed:false |
|||||
Name |
Required |
Default |
Evaluated |
Type |
Description |
---|---|---|---|---|---|
id | false | false | String | Deprecated. Use 'var' instead | |
name | false | false | String | Deprecated. Use 'var' instead | |
scope | false | action | false | String | The scope in which to assign the variable. Can be application, session, request, page, or action. |
value | false | false | String | The value that is assigned to the variable named name | |
var | false | false | String | Name used to reference the value pushed into the Value Stack |
<s:set name="personName" value="person.name"/> Hello, <s:property value="#personName"/>. How are you?