Java Reference
In-Depth Information
Servlets also require the services of a Java programmer any time the HTML needs to be
changed. The servlet must be edited, recompiled, and deployed on the Web, and few
organizations would be comfortable handing that task to a nonprogrammer.
JSP is a complement to servlets rather than a replacement. They make it easy to separate
two kinds of web content:
Static content, the portions of a web page that don't change, such as an online
store's description of each product
n
Dynamic content, the portions of a web page generated by a servlet, such as the
store's pricing and availability data for each product, which can change as items
sell out
n
When you use only servlets on a project, it becomes difficult to make minor changes,
such as correcting a typo in text, rewording a paragraph, or altering some HTML tags to
change how the page is presented. Any kind of change requires the servlet to be edited,
compiled, tested, and redeployed on the web server.
With JSP, you can put the static content of a web page in an HTML document and call
servlets from within that content. You also can use other parts of the Java language on a
page, such as expressions, if - then blocks, and variables. A web server that supports the
Tomcat specification knows how to read these pages and execute the Java code they con-
tain, generating an HTML document as if you wrote a servlet to handle the whole task.
In actuality, JSP uses servlets for everything.
You create a JSP page as you would create an HTML document—in a text editor or web
publishing program such as Macromedia Dreamweaver. When you save the page, use the
.jsp file extension to indicate that the file is a JSP page instead of an HTML document.
Then, the page can be published on a web server like an HTML document, as long as the
server supports servlets and JSP.
When a user requests the page for the first time, the web server compiles a new servlet
that presents the page. This servlet combines everything that has been put into the page:
Text marked up with HTML
n
Calls to Java servlets
n
Java expressions and statements
n
21
Special JSP variables
n
Search WWH ::




Custom Search