Datasheet
Patrick c01.tex V3 - 09/18/2009 12:15pm Page 8
Chapter 1: Building Web Applications in WebLogic
JSP Pages Are Converted to Servlets
The key to understanding JSP pages is to recognize that the JSP file itself is simply the input for
a multistep process yielding a servlet. In the key processing step, the JSP page is parsed by the
application server and converted to the equivalent pure Java servlet code. All text that is not
part of JSP tags and scripting elements is assumed to be part of the HTTP response. This text is
placed in output writing calls within the generated servlet method that processes requests. All Java
scripting elements and tags become additional Java code in the servlet. The generated servlet is
then compiled, loaded, and used to process the HTTP request in a manner identical to a normal
servlet.
Figure 1-1 depicts this process for a trivial JSP page with a small amount of scripted Java
code embedded on the page. The
sample.jsp
page is converted to the equivalent pure Java
servlet code, compiled into a servlet class, and used to respond to the original and subsequent
HTTP requests.
sample.jsp
<html>
<head>
<title>A Sample Servlet</title>
</head>
<body>
<H1>A Sample JSP Page</H1>
<H2>Counting Fun</H2>
<% for (int jj=1; jj<=10; jj++) { %>
<%= jj %><br>
<% } %>
</body>
</html>
<html>
. . .
<H2>Counting Fun</H2>
1<br>
2<br>
. . .
</html>
_sample.java
_sample.class
Servlet Source Code
Servlet Class
HTTP Response
HTTP Request
from Browser
Figure 1-1: JSP page is converted to a servlet.
The parsing, conversion, compiling, and classloading steps required to accomplish this transforma-
tion are handled by the application server. You don’t have to perform any of these steps ahead of
time or register the resulting servlet — all of this is done automatically by the server. Note that the
processing and compiling can be done prior to deployment using utilities provided by WebLogic
Server, a technique known as precompiling the JSP pages.
In WebLogic Server, the resulting servlet is a subclass of
weblogic.servlet.jsp.JspBase
by
default.
JspBase
is a WebLogic-provided class that extends
HttpServlet
and forwards
service()
calls to a method called _
jspService()
. You may also create a custom base class for JSP-generated
servlets to replace the default
JspBase
class.
Many Tags and Scripting Elements Are Available
JSP technology provides a rich set of scripting elements and tags for creating dynamic content.
Table 1-2 lists some of the important elements available.
8