1.4.3
Objects and Scopes
A JSP page can create and/or access some Java objects when processing a request.  The JSP 
specification indicates that some objects are created implicitly, perhaps as a result of a 
directive (see Section 2.8,  Implicit Objects ); other objects are created explicitly through 
actions; objects can also be created directly using scripting code, although this is less 
common. The created objects have a 
scope attribute 
defining 
where
 there is a reference to the 
object and 
when
 that reference is removed
.
The created objects may also be visible directly to the scripting elements through some 
scripting level variables (see Section 1.4.7,  Objects and Variables ).
Each action and declaration defines, as part of its semantics, what objects it defines, with 
what scope attribute, and whether they are available to the scripting elements.
Objects are always created within some JSP page instance that is responding to some 
request
object. There are several scopes:
page
   Objects with 
page
 scope are accessible only within the page where they are 
created. All references to such an object shall be released after the response is sent back 
to the client from the JSP page or the request is forwarded somewhere else. References to 
objects with 
page
 scope are stored in the 
pageContext
 object.
request 
  Objects with 
request
 scope are accessible from pages processing the same 
request where they were created. All references to the object shall be released after the 
request is processed; in particular, if the request is forwarded to a resource in the same 
runtime, the object is still reachable. References to objects with 
request
 scope are stored 
in the 
request
 object.
session
   Objects with 
session
 scope are accessible from pages processing requests that 
are in the same session as the one in which they were created. It is not legal to define an 
object with session scope from within a page that is not session aware (see Section 2.7.1, 
 The page Directive ). All references to the object shall be released after the associated 
session ends. References to objects with 
session
 scope are stored in the 
session
 object 
associated with the page activation.
application
   Objects with 
application
 scope are accessible from pages processing 
requests that are in the same application as they one in which they were created. All 
references to the object shall be released when the runtime environment reclaims the 
ServletContext
. Objects with application scope can be defined (and reached) from 
pages that are not session aware. References to objects with 
application
 scope are stored 
in the 
application
object associated with a page activation.
A 
name
 should refer to a unique object at all points in the execution, i.e. all the different 
scopes really should behave as a single name space. A JSP container implementation may or 
not enforce this rule explicitly due to performance reasons.
Chapter 1
Overview
24




JSP Web Hosting JavaServer Pages Specifications JSP Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.