Implicit JSP Scripting Objects

Scripting elements can use predefined variables that the container assigns as references to implicit objects (Table 16-1) to access request and application data. These objects are instances of classes defined by the servlet and JSP specifications. Appendix D contains complete descriptions of all methods for each class, and they are briefly introduced here and used in a number of examples in this chapter.

Table 16-1. Implicit JSP objects

Variable name

Java type

application
javax.servlet.ServletContext
config
javax.servlet.ServletConfig
exception
java.lang.Throwable
out
javax.servlet.jsp.JspWriter
page
java.lang.Object
pageContext
javax.servlet.jsp.PageContext
request
javax.servlet.http.HttpServletRequest
response
javax.servlet.http.HttpServletResponse
session
javax.servlet.http.HttpSession

These objects provide access to the same information (and more) as the implicit variables you can use in EL expressions, but it’s not a one-to-one match:

pageContext

The pageContext variable contains a reference to an instance of the class named javax.servlet.jsp.PageContext. It provides methods for accessing references to all the other objects and attributes for holding data that is shared between components in the same page. It’s the same object that you can access with the ${pageContext} EL expression. Attribute values for this object represent the page scope; they are the same objects as are available to the EL world as a Map represented by ...

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.