SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 461 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"


The target attribute must be an expression that evaluates to some object. If the
object implements the Map interface, the property attribute of the c:set tag is
treated as a key with which to create a new map entry with the value specified. If the
target evaluates to a JavaBean, the value of the c:set tag is passed to the property
of the target JavaBean specified by the property attribute.
When the value of the c:set tag evaluates to null, the effect is no different then
invoking someScopeReference.setAttribute(null), where some-
ScopeReference is one of request, response, session, and so on, which essentially
removes the attribute from that scope. For convenience, JSTL provides an explicit
c:remove tag. The c:remove tag allows the JSP author to specify the name of the
attribute to remove using the required var attribute and the scope to remove it from
using the optional scope attribute. Unlike the c:set tag, if the scope attribute is
not specified, the c:remove tag will remove the attribute from all scopes.
Listing 9.5 shows set.jsp as an example of how c:set and c:remove can be used.
First, we use the c:set tag to create an attribute called map (of type HashMap) and
store it in the request scope. We populate the map using the c:set tag as well.
The first element in the map is partialTitle, which contains only part of this
book??™s title. The fullTitle element is comprised from the partialTitle element
plus the second part of the title.


Pages:
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473