JSP.3.1 The JSP Page Model


As indicated in Section JSP.1.4, "Overview of JSP Page Semantics," a JSP page is executed by a JSP container, which is installed on a web server or web enabled application server. The JSP container delivers requests from a client to a JSP page and responses from the JSP page to the client. The semantic model underlying JSP pages is that of a servlet: a JSP page describes how to create a response object from a request object for a given protocol, possibly creating and/or using in the process some other objects. A JSP page may also indicate how some events (in JSP 1.1 only init and destroy events) are to be handled.

JSP.3.1.1 The Protocol Seen by the Web Server

The entity that processes request objects creating response objects should behave as if it were a Java technology-based class; in this specification we will simply assume it is so. This class must implement the servlet protocol. It is the role of the JSP container to first locate the appropriate instance of such a class and then deliver requests to it according to the servlet protocol. As indicated elsewhere, a JSP container may need to create such a class dynamically from the JSP page source before delivering request and response objects to it.

Thus, servlet defines the contract between the JSP container and the JSP page implementation class. When the HTTP protocol is used, the contract is described by the HttpServlet class. Most pages use the HTTP protocol, but other protocols are allowed by this specification.

JSP.3.1.2 The Protocol Seen by the JSP Page Author

The JSP specification also defines the contract between the JSP container and the JSP page author. This is, what assumptions can an author make for the actions described in the JSP page?

The main portion of this contract is the jspService() method that is generated automatically by the JSP container from the JSP page. The details of this contract are provided in Chapter JSP.4.

The contract also describes how a JSP author can indicate that some actions must be taken when the init() and destroy() methods of the page implementation occur. In JSP 1.1 this is done by defining methods with name jspInit() and jspDestroy() in a declaration scripting element in the JSP page. Before the first time a request is delivered to a JSP page a jspInit() method, if present, will be called to prepare the page. Similarly, a JSP container can reclaim the resources used by a JSP page at any time that a request is not being serviced by the JSP page by invoking first its jspDestroy() method, if present.

A JSP page author may not (re)define any of the servlet methods through a declaration scripting element.

The JSP specification reserves the semantics of methods and variables starting with jsp , _jsp , jspx , and _jspx , in any combination of upper- and lower-case .

JSP.3.1.3 The HttpJspPage Interface

The enforcement of the contract between the JSP container and the JSP page author is aided by requiring that the servlet class corresponding to the JSP page implement the HttpJspPage interface (or the JspPage interface if the protocol is not HTTP).

The involved contracts are shown in Figure JSP.3-1. We now revisit this whole process in more detail.

Figure JSP.3-1. Contracts Between a JSP Page and a JSP Container



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net