Using Objects Within JSP Pages

You can access a variety of objects, including enterprise beans and JavaBeans components, within a JSP page. JSP technology automatically makes some objects available and you can also create and access application-specific objects.

Implicit Objects

Implicit objects are created by the web container and contain information related to a particular request, page, or application. Many of the objects are defined by the Java Servlet technology underlying the JSP technology.

Table 17 below lists some implicit objects.

Table 17 Implicit Objects 
Variable
Class
Description
application
javax.servlet.
ServletContext

The context for the JSP page's servlet and any web components contained in the same application.
config
javax.servlet.
ServletConfig

Initialization information for the JSP page's servlet.
exception
java.lang.
Throwable

Accessible only from an error page. See Handling Errors.
out
javax.servlet.
jsp.JspWriter

The output stream.
request
subtype of
javax.servlet.
ServletRequest

The request triggering the execution of the JSP page.
response
subtype of
javax.servlet.
ServletResponse

The response to be returned to the client. Not typically used by JSP page authors.
session
javax.servlet.
http.HttpSession

The session object for the client.

Application-Specific Objects

When possible, application behavior should be encapsulated in objects so that page designers can focus on presentation issues. Objects can be created by developers who are proficient in the Java programming language and accessing databases and other services. There are four ways to create and use objects within a JSP page:

Declarations, scriptlets, and expressions are described in JSP Scripting Elements.


From the J2EE Tutorial section on JavaServer Pages Technology by Stephanie Bodoff.

Maintained by John Loomis, last updated 31 March 2001