Name

<c:set>

Synopsis

The <c:set> action sets a scoped variable or a property of a target object to the value of an expression evaluation result. The target object must be a java.util.Map or a bean with a matching property setter method.

If the evaluation result is null, the variable is removed or the property is reset (removed or set to null, depending on the type of target). Otherwise, when setting a variable or a Map entry, the type of the value is the type of the expression evaluation value. When setting a bean property, the expression evaluation value is coerced to the property type according to the rules described in Appendix C.

Syntax 1: Setting a variable, without a body

<c:set value="expression" var="var"
  [scope="page|request|session|application"] />

Syntax 2: Setting a variable, with a body

<c:set var="var" [scope="page|request|session|application"]>
  JSP elements
</c:set>

Syntax 3: Setting a property, without a body

<c:set value="expression" target="beanOrMap" property="propertyName" />

Syntax 4: Setting a property, with a body

<c:set target="beanOrMap" property="propertyName">
  JSP elements
</c:set>

Attributes

Attribute name

Java type

Dynamic value accepted

Description

value
Object

Yes

The expression to use as the value.

var
String

No

The name of the variable.

scope
String

No

Scope for the variable.

target
Object

Yes

The target object, either a java.util.Map or a bean with a setter method for property.

property
String

Yes

The target object’s property name. ...

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.