Oracle JavaServer Pages Developer's Guide and Reference Release 8.1.7 Part Number A83726-01 |
|
This section provides a top-level look at how a JSP is run, including on-demand translation (the first time a JSP page is run), the role of the JSP container and the servlet container, and error processing.
A JSP container is an entity that translates, executes, and processes JSP pages and delivers requests to them.
The exact make-up of a JSP container varies from implementation to implementation, but it will consist of a servlet or collection of servlets. The JSP container, therefore, is executed by a servlet container. (Servlet containers are summarized in "Servlet Containers".)
A JSP container may be incorporated into a Web server if the Web server is written in Java, or the container may be otherwise associated with and used by the Web server.
Presuming the typical on-demand translation scenario, a JSP page is usually executed through the following steps:
.jsp
file name.
.jsp
file name extension in the URL, the servlet container of the Web server invokes the JSP container.
.java
file and then compiling the .java
file to produce a servlet .class
file.
The servlet class generated by the JSP translator subclasses a class (provided by the JSP container) that implements the javax.servlet.jsp.HttpJspPage
interface (described in "Standard JSP Interfaces and Methods"). The servlet class is referred to as the page implementation class. This document will refer to instances of page implementation classes as JSP page instances.
Translating a JSP page into a servlet automatically incorporates standard servlet programming overhead into the generated servlet code, such as implementing the javax.servlet.jsp.HttpJspPage
interface and generating code for its service method.
The servlet (JSP page instance) will then process the HTTP request, generate an HTTP response, and pass the response back to the client.
A JSP page can be requested either directly--through a URL--or indirectly--through another Web page or servlet.
As with a servlet or HTML page, the end-user can request a JSP page directly by URL. For example, assume you have a HelloWorld
JSP page that is located under the myapp
application root directory in the Web server, as follows:
myapp/dir1/HelloWorld.jsp
If it uses port 8080 of the Web server, you can request it with the following URL:
http://hostname:8080/myapp/dir1/HelloWorld.jsp
(The application root directory is specified in the servlet context of the application. "Servlet Contexts" summarizes servlet contexts.)
The first time the end-user requests HelloWorld.jsp
, the JSP container triggers both translation and execution of the page. With subsequent requests, the JSP container triggers page execution only; the translation step is no longer necessary.
JSP pages, like servlets, can also be executed indirectly--linked from a regular HTML page or referenced from another JSP page or from a servlet.
When invoking one JSP page from a JSP statement in another JSP page, the path can be either relative to the application root--known as context-relative or application-relative--or relative to the invoking page--known as page-relative. An application-relative path starts with "/"; a page-relative path does not.
Be aware that, typically, neither of these paths is the same path as used in a URL or HTML link. Continuing the example in the preceding section, the path in an HTML link is the same as in the direct URL request, as follows:
<a href="/myapp/dir1/HelloWorld.jsp" /a>
The application-relative path in a JSP statement is:
<jsp:include page="/dir1/HelloWorld.jsp" flush="true" />
The page-relative path to invoke HelloWorld.jsp
from a JSP page in the same directory is:
<jsp:forward page="HelloWorld.jsp" />
("JSP Actions and the <jsp: > Tag Set" discusses the jsp:include
and jsp:forward
statements.)
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|