Learn Java for Web Development

(Tina Meador) #1

80 CHAPTER 2: Building Web Applications Using Servlets and JSP


Note In addition to the standard servlet request, session, and application scopes, JSP adds a fourth scope
called page scope.

A JSP page can access some specific objects through scripting variables. These objects are
provided by the JSP container and are called implicit objects. These implicit objects can be
accessed in scriptlets, in expressions, or as part of the EL expressions. (The EL expressions are
introduced in Chapter 3.) Table 2-5 lists the nine implicit objects with the corresponding API.


Table 2-4. Scope Objects


Scope Objects Servlet API Accessible From...
Application/web
context

javax.servlet.ServletContext Web components across the application

Request Subtype of javax.servlet.ServletRequest Web components that handle the request
Session javax.servlet.http.HttpSession Web components in a session
Page javax.servlet.jsp.JspContext The JSP page that creates the object

Table 2-5. Implicit Objects
Implicit Object Usage API
application Accesses application-level objects ServletContext
config Provides configuration information ServletConfig
exception Accesses error status JSPException
out Accesses the JSP output stream JSPWriter
page Provides a reference to the current JSP Object
pageContext Accesses the JSP container PageContext
request Provides access to the client request ServletRequest
response Provides access to the JSP response ServletResponse
session Shares information across client requests HttpSession

These implicit objects are described in more detail in the following sections.


application


The implicit application object provides a reference to the javax.servlet.ServletContext interface.
The ServletContext interface is used to provide access to any context-initialization parameters that
have been configured for the JSP page via the deployment descriptor of the web application. The
ServletContext object and parameters stored in them by the web container are available to the
entire web application. The application object provides the developer of the JSP page with access
to the ServletContext object.

Free download pdf