Java Reference
In-Depth Information
Sidebar 16.3 Database resources in JSP
The use of a database from a Java web application is more complex than the use
of a JDBC connection from a normal Java program. It requires setting up a
resource that will be used by the web application.
The exact configuration depends on the container and database. Here we
assume the use of the Tomcat servlet and JSP container, an open source that is
freely available from the Jakarta Project, The database
we use is the Cloudscape DB that is bundled with the Java 2 SKD Enterprise
First, we need to make the database jar files available to the web container. In
our case we have to copy the cloudscape.jar and the RmiJdbc.jar files to the
common lib directory of Tomcat.
Then we need to declare a DataSource in the configuration of the JSP container.
In our case we need to add the following fragment to the server.xml file:
<Resource name # "jdbc/CloudscapeDB" auth # "Container"
type # "javax.sql.DataSource" scope # "Shareable"/>
<ResourceParams name # "jdbc/CloudscapeDB">
Finally the descriptor of the application must include a reference to the
resource declared in the container configuration. The web.xml
file of the
application contains an entry like this:
The Cloudscape DB is based on the RmiJdbc connector, thus the database runs as
a separate process. Before starting the server we need to start the Cloudscape DB
with the cloudscape -start command from the bin directory of the J2SDKEE.
The JSP login authenticates the user and, in the case of success, redirects
the user's browser to the main page; the authentication is performed by the
object manager of class Manager that is registered in the application context.
If the authentication is successful the user object is registered in the session
Search WWH ::

Custom Search