Apache Struts 2 Documentation > Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > Generic Tag Reference > set |

Apache Struts 2 Documentation
set
Edit Page Browse Space Add Page Add News
Added by digi9ten, last edited by Don Brown on Jan 06, 2007 (view change)

| Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

# Description

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).

The scopes available are as follows :-

- application - the value will be set in application scope according to servlet spec. using the name as its key
- session - the value will be set in session scope according to servlet spec. using the name as key
- request - the value will be set in request scope according to servlet spec. using the name as key
- page - the value will be set in request scope according to servlet sepc. using the name as key
- action - the value will be set in the request scope and Struts' action context using the name as key

NOTE:

If no scope is specified, it will default to action scope.

# Parameters

#### Name | #### Required | #### Default | #### Evaluated | #### Type | #### Description
--- | --- | --- | --- | --- | ---
id | false |  | true | String | id for referencing element. For UI and form tags it will be used as HTML id attribute
name | true |  | true | String | The name of the new variable that is assigned the value of value
scope | false | action | true | String | The scope in which to assign the variable. Can be application, session, request, page, or action.
value | false |  | true | String | The value that is assigned to the variable named name

# Examples

    <s:set name="personName" value="person.name"/>
    Hello, <s:property value="#personName"/>. How are you?