Database Reference
In-Depth Information
Java JSP scripts are compiled into Java servlets and run inside a process known as a
servlet container. The first time a client requests a given JSP page, the container compiles
the page into a servlet in the form of executable Java byte code before loading and
running it. The container caches the byte code so that the script can run directly with
no compilation phase for subsequent requests. If you modify the script, the container
notices this when the next request arrives, recompiles the script into a new servlet, and
reloads it. The JSP approach provides a significant advantage over writing servlets di‐
rectly, because you need not compile code yourself or handle servlet loading and un‐
loading. Tomcat handles the responsibilities of both the servlet container and the web
server that communicates with the container.
This section provides an overview of JSP programming with Tomcat, but makes several
assumptions:
• You are familiar with the concepts underlying JavaServer Pages, such as what a
servlet container is, what an application context is, and what the basic JSP scripting
elements are.
• The Tomcat server has been installed so that you can execute JSP pages, and you
know how to start and stop it.
• You are familiar with the Tomcat webapps directory and how Tomcat applications
are structured.
• You know what a tag library is, how to use one, and are familiar with the JSP Stan‐
dard Tag Library (JSTL).
I recognize that is a lot to assume. If you're unfamiliar with JSP or JSTL, or need in‐
structions for installing Tomcat, read “JSP, JSTL, and Tomcat Primer” on the companion
website for the necessary background information (see the Preface ).
Once you have Tomcat in place, install the following components so that you can work
through the JSP examples in this topic:
• The mcb sample application. This is located in the tomcat directory of the rec
ipes distribution.
• A MySQL JDBC driver. You might already have one installed for use with the scripts
in earlier chapters, but Tomcat needs a copy, too. This topic uses MySQL Connector/
J.
• The JSTL tag library, which contains tags for performing database activities, con‐
ditional testing, and iterative operations within JSP pages.
This section discusses how to install these components and describes how to write the
JSP equivalent of the MySQL table-display script that was implemented in Recipe 18.2
using Perl, Ruby, PHP, and Python.
Search WWH ::




Custom Search