Java Reference
In-Depth Information
The <c:set>Action
The JSTL set tag or the <c:set> action sets the value of a scoped variable or a property of a target
object. The <c:set> action is a better alternative to using the <jsp:setProperty> JSP action. Unlike
<jsp:setProperty> , which allows you to set only the bean property, the <c:set> tag can do the following:
Set bean properties
Set Map values
Table 3-10 describes the attributes of the <c:set> action.
Create scoped variables on the page, request, session, or application scope
Table 3-10. <c:set>Attributes
Name
Type
Description
value
Object
Expression to be evaluated.
var
String
Name of the exported scoped variable to hold the value specified in the action.
scope
String
Scope for var .
target
Object
Target object whose property will be set. This must evaluate to a JavaBeans object
with the setter property property or to a java.util.Map object.
property
String
Name of the property to be set in the target object.
The <c:set> tag is used to do the following:
Set the value of a scoped variable in any JSP scope.
Set a property of a specified target object. The target must evaluate to a
JavaBean or Map object.
Setting the Value of a Scoped Variable in Any JSP Scope
One of the tasks of the <c:set> action is to set variables that can be used by other actions on pages.
Here's the syntax:
<c:set value=""value""var=""varName" " [scope=""{page|request|session|application}""]/>
Listing 3-36 shows an example of using <c:set> to set the value of the scoped variable helloVar .
Listing 3-36. Using <c:set>
<c:set var="helloVar" value="hello" />
Listing 3-36 creates an attribute named helloVar with the value "hello" in the default scope, which
is page scope. You can also create attributes in another scope, say session scope; in that case, you
need to specify the scope with <c:set> attribute scope ="". Listing 3-37 creates a variable on session
scope using <c:set> .
 
 
Search WWH ::




Custom Search