JSP.2.5 Overview of Semantics


A JSP page describes how to create a response object from a request object for a given protocol, possibly creating and/or using some other objects. A JSP page is executed by a JSP container; requests sent to a JSP page are delivered by the JSP container to some JSP page implementation instance that is a subclass of servlet (see Chapter JSP.3).

JSP.2.5.1 Web Applications

A web application is a collection of resources that are available through some URLs. The resources include JSP pages, Java servlet classes, static pages, and other Java technology-based resources and classes to be used at the server-side as well as Java resources and classes (like applets, JavaBeans components , and others) which are to be downloaded for use by the client. A web application is described in more detail in Chapter SRV.9 of the Servlet 2.2 specification.

A web application contains a deployment descriptor web.xml that contains information about the JSP pages, servlets, and other resources used in the web application. The deployment descriptor is described in detail in Chapter SRV.13 of the Servlet 2.2 specification.

JSP 1.1 requires that all these resources are to be implicitly associated with and accessible through a unique ServletContext instance, which is available as the application implicit object (Section JSP.2.8). The JSP specification inherits the notions of a web application from the Servlet 2.2 specification.

The application to which a JSP page belongs is reflected in the application object and has impact on the semantics of the following elements:

  • The include directive (Section JSP.2.7.6)

  • The jsp:include action element (Section JSP.2.13.4)

  • The jsp:forward action (Section JSP.2.13.5)

JSP.2.5.2 Relative URL Specifications Within an Application

Elements may use relative URL specifications , which are called "URI paths" in the Servlet 2.1 specification. These paths are as in RFC 2396 specification, i.e., only the path part, no scheme or authority. Some examples are:

 "myErrorPage.jsp"  "/errorPages/SyntacticError.jsp"  "/templates/CopyrightTemplate.html" 

When such a path starts with a "/", it is to be interpreted by the application to which the JSP page belongs; i.e., its ServletContext object provides the base context URL. We call these paths "context-relative paths."

When such a path does not start with a "/", it is to be interpreted relative to the current JSP page: the current page is denoted by some path starting with "/" which is then modified by the new specification to produce a new path that starts with "/"; this final path is the one interpreted through the ServletContext object. We call these paths "page-relative paths."

The JSP specification uniformly interprets all these paths in the context of the web server where the JSP page is deployed; i.e., the specification goes through a map translation. The semantics applies to translation-time phase (i.e., include directives, Section JSP.2.7.6), and to request-time phase (i.e., to include, Section JSP.2.13.4, and forward, Section JSP.2.13.5, actions).

If a specific tool can ascertain by some mechanism the status of the URL to resource maps at deployment time, the tool can take advantage of this information.

With the appropriate assertions, the translation phase might be performed before deploying the JSP page into the JSP container.

JSP.2.5.3 Web Containers and Web Components

A JSP container is a system-level entity that provides life-cycle management and runtime support for JSP pages and servlet components. The term web container is synonymous with JSP container.

A web component is either a servlet or a JSP page. A web component may use the services of its container. The servlet element in a web.xml deployment descriptor is used to describe both types of web components; note that most JSP page components are defined implicitly in the deployment descriptor through the use of an implicit .jsp extension mapping.

JSP.2.5.4 JSP Pages

A JSP page implementation class defines a jspService() method mapping from the request to the response object. Some details of this transformation are specific to the scripting language used; see Chapter JSP.4. Most details are not language specific and are described in this chapter.

Most of the content of a JSP page is devoted to describing what data is written into the output stream of the response (usually sent back to the client). The description is based on a JspWriter object that is exposed through the implicit object out (see Section JSP.2.8, "Implicit Objects"). Its value varies:

  • Initially, out is a new JspWriter object. This object may be different from the stream object from response.getWriter() , and may be considered to be interposed on the latter in order to implement buffering (see Section JSP.2.7.1, "The page Directive"). This is the initial out object. JSP page authors are prohibited from writing directly to either the PrintWriter or OutputStream associated with the ServletResponse .

  • Within the body of some actions, out may be temporarily re-assigned to a different (nested) instance of JspWriter object. Whether this is or is not the case depends on the details of the action semantics. Typically, the content, or the results of processing the content, of these temporary streams is appended to the stream previously referred to by out , and out is subsequently reassigned to refer to that previous (nesting) stream. Such nested streams are always buffered and require explicit flushing to a nesting stream or discarding of their contents.

  • If the initial out JspWriter object is buffered, then depending upon the value of the autoFlush attribute of the page directive, either the content of that buffer will be automatically flushed out to the ServletResponse output stream to obviate overflow, or an exception shall be thrown to signal buffer overflow. If the initial out JspWriter is unbuffered, then content written to it will be passed directly through to the ServletResponse output stream.

A JSP page can also describe what should happen when some specific events occur. In JSP 1.1, the only events that can be described are initialization and destruction of the page; these are described using "well-known method names " in declaration elements (see Section JSP.3.1.2). Future specifications will likely define more events as well as a more structured mechanism for describing the actions to take.



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