Database Reference
In-Depth Information
Installing the mcb application
Web applications for Tomcat typically are packaged as WAR (web archive) files and
installed under its
webapps
directory, which is roughly analogous to Apache's
htdocs
document root directory. The
recipes
distribution includes a sample application
named
mcb
to use for the JSP examples described here. Look in the distribution's
tom
cat
directory, where you will find a file named
mcb.war
. Copy that file to Tomcat's
webapps
directory and restart Tomcat.
As distributed, Tomcat is configured by default to look for WAR files under
webapps
when it starts and automatically unpack any that have not already been unpacked. This
means that restarting Tomcat after copying
mcb.war
to the
webapps
directory should
be enough to unpack the
mcb
application. When Tomcat finishes its startup sequence,
look under
webapps
and you should see a new
mcb
directory under which are all the
files contained in
mcb.war
. Explore the
mcb
directory if you like. It should contain
several files that clients can request using a browser. There should also be a
WEB-INF
subdirectory, which is used for information that is private—that is, available for use by
scripts in the
mcb
directory, but not directly accessible by clients.
Next, to verify that Tomcat can serve pages from the
mcb
application context, request
some of them from your browser. The main
mcb
page is:
http://localhost:8080/mcb/
The following URLs request in turn a simple static HTML page, servlet, and JSP page
(each is available from the main page):
http://localhost:8080/mcb/simple.html
http://localhost:8080/mcb/servlet/SimpleServlet
http://localhost:8080/mcb/simple.jsp
Adjust the hostname and port number in the URLs appropriately for your installation.
Installing the JDBC driver
Some JSP pages in the
mcb
application need a JDBC driver for connecting to the
cook
book
database. This topic uses the MySQL Connector/J driver.
To install Connector/J for use by Tomcat applications, place a copy of it in Tomcat's
directory tree. Assuming that the driver is packaged as a JAR file (as is the case for
Connector/J), there are different places under the Tomcat root directory where you can
install it, depending on how visible you want the driver to be:
•
To make the driver available only to the
mcb
application, place it in the
mcb/WEB-
INF/lib
directory under Tomcat's
webapps
directory.
• To make the driver available both to Tomcat and to applications, place it in the
lib
directory under the Tomcat root.