Two Laptop Bag
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes <c:set var Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "<c:set var" Watch "<c:set var" New topic

<c:set var

Aditi Kamra

Joined: Aug 25, 2009
Posts: 7

I have a doubt about c:set with the "var" version (<c:set var="name" value=""/>

If the value evaluates to null , and the scope is not mentioned , I understood from HFSJ that it will start looking in all the scopes starting from page scope, so if this var is present in more than one scope, will it remove it from all scopes(like c:remove does when scope is not mentioned) or just the one it encounters first ?

Might be a silly doubt but can somebody please clear this out ..

Thanks in Advance

Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

From the JSTL spec

If value is null
Syntax 1: the scoped variable defined by var and scope is removed.
* If attribute scope is specified, the scoped variable is removed according to
the semantics of PageContext.removeAttribute(varName, scope).
* Otherwise, the scoped variable is removed according to the semantics of

So the attribute will be removed from all the scopes. The following is from the java documentation of PageContext.removeAttribute(String)

Remove the object reference associated with the given name from all scopes. Does nothing if there is no such object.

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: <c:set var
It's not a secret anymore!