JSP Implicit Objects

The JSP specification makes 9 built-in objects available to the developer. These objects, provided by the Java API without any additional implementation, provide administrative and utility services to the JSP page. These implicit objects are detailed in Table 15.7.

Table 15.7. JSP Configuration Parameters
ObjectClass and DescriptionScope (Refer to Table 15.5)
requestjavax.servlet.http.HttpServletRequest. Triggers service invocation. Usually implemented to reference client information within the request.Request
responsejavax.servlet.http.HttpServletResponse. Response to client request. Encapsulates response data associated with client request. Rarely used in development.Page
pageContextJava.servlet.jsp.PageContext. JSP page context. Contains JSP implementation-dependent features, such as optimized JSP writers. Implemented to create other implicit objects.Page
applicationjavax.servlet.ServletContext. The Servlet context obtained from servlet configuration object. Usually implemented to track data at application scope.Application
outJavax.servlet.jsp.JspWriter. Writes to output stream. It has methods to write out the primitive data types, Objects, and Strings. Sometimes used as an output object for formatting classes, or for controlling the output buffer.Page
configJavax.servlet.ServletConfig. JSP page ServletConfig. May be implemented to access servlet initialization parameters, normally not used in development.Page
PageJava.lang.Object. De facto “this” reference for the page; generally not used in development.Page
sessionjavax.servlet.http.HttpSession. Client session object; HTTP protocol only. Usually implemented to track data session scope data. More information provided later in this chapter.Session
exceptionJava.lang.Throwable. Uncaught throwable which results in error page invocation. May be used in JSP page exception handling.Page

The session object instances of HttpSession (via the HttpServletRequest) are the most commonly used implicit object in JSP page development. Weblogic Server supports JSP sessions according to JSP 1.l. Session objects may be used to store small, short-lived objects within the session.

What's a small and short-lived object? You must use your own judgment based upon the performance metrics of your application and the importance of the data. However, large or valuable objects should be stored in a database. This is because JSP sessions are not persisted and there can be a performance bottleneck. For example, you should not store an existing order's line items in a session. They may be lost if the server crashes, and they can take a lot of space, which may slow down the system. However, it's a good idea to store the order in an Entity EJB, and to store the EJB's primary key in the session while it is used.

Objects stored in a session make user-defined or other objects available across several resources; that is, objects stored in one JSP page are available to other JSP pages, servlets, and static HTML pages within the same session. If the session data is a user-defined data type, the class should implement the Java Serializable interface. See lines 15 and 22 of Listing 15.3 for an example of session creation and use. The request object is also heavily used in JSP page development. For details on HttpServletRequest and HTTPSession refer to Chapter 14, “Writing WebLogic Server Servlets,” and the JavaSoft documentation site at http://java.sun.com/products/servlet.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset