The Java EE 5 Tutorial

Using Scope Objects

Collaborating web components share information by means of objects that are maintained as attributes of four scope objects. You access these attributes using the [get|set]Attribute methods of the class representing the scope. Table 4–3 lists the scope objects.

Table 4–3 Scope Objects

Scope Object 

Class 

Accessible From 

Web context 

javax.servlet.ServletContext

Web components within a web context. See Accessing the Web Context.

Session 

javax.servlet.http.HttpSession

Web components handling a request that belongs to the session. See Maintaining Client State.

Request 

subtype of javax.servlet.ServletRequest

Web components handling the request. 

Page 

javax.servlet.jsp.JspContext

The JSP page that creates the object. See Using Implicit Objects.

Figure 4–1 shows the scoped attributes maintained by the Duke’s Bookstore application.

Figure 4–1 Duke’s Bookstore Scoped Attributes

Diagram of Duke's Bookstore scoped attributes. Session
attributes are currency and cart, web context attributes are hitCounter, bookDB,
orderCounter.