Cover of JSP 2.0 - The Complete Reference

Case Study: Product Support Center

Installation and Customization

This document describes how to install and customize the Product Support Center web application described in Chapter 19.

Note: Every configuration is a little bit different, depending on your operating system, your servlet engine, etc. If you run into difficulties, consult the appropriate chapters of the book and your software documentation. If you find a bug (or better yet, if you fix one), please let me know so that I can update the source.

Software Requirements

  • Java 2 (at least JDK 1.4)
  • A servlet engine that supports Servlet API 2.4. I recommend Tomcat 5 for this purpose.
  • A database management system with a JDBC driver (MySQL recommended)

Installing the Database

  • To run the application, you need a database management system with a JDBC driver. Any one will do; if you have Microsoft Access, you can use the JDBC-ODBC bridge. For this book, I have used the MySQL database, which is freely downloadable from http://www.mysql.com.
  • The SQL necessary to create and load the database are in the source code zip file, in the jspcr2/database/casestudy directory.

Installing the Web Application

  • The source code zip file contains all source code listed in the book. The case study is in the jspcr2/chap19/casestudy directory. There is a build.xml file in the WEB-INF subdirectory, which can be run with Jakarta Ant to compile the source and create the support.jar file.
  • After compiling the application, deploy it as a web application according to the instructions in your servlet engine's documentation.

Modifications to Servlet Engine configuration

  • The web.xml deployment descriptor uses a <resource-ref> section to specify the JDBC data source being used:
       <resource-ref>
          <description>Product support database</description>
          <res-ref-name>jdbc/LyricNote</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
       </resource-ref>
                
    You will need to configure the corresponding entries in your servlet engine configuration to equate this to an actual data source. For Tomcat 5, here is what I use in $TOMCAT/conf/server.xml to configure the case study context:
       <Context
             path="/support"
             docBase="D:/website/src/jspcr2/source/jspcr2/chap19/casestudy"
             >
          <Resource
                name="jdbc/LyricNote"
                auth="Container"
                type="javax.sql.DataSource"
                />
          <ResourceParams name="jdbc/LyricNote">
             <parameter>
                <name>factory</name>
                <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
             </parameter>
             <parameter>
                <name>maxActive</name>
                <value>100</value>
             </parameter>
             <parameter>
                <name>maxIdle</name>
                <value>30</value>
             </parameter>
             <parameter>
                <name>maxWait</name>
                <value>10000</value>
             </parameter>
             <parameter>
                <name>username</name>
                <value>author</value>
             </parameter>
             <parameter>
                <name>password</name>
                <value>goodness</value>
             </parameter>
             <parameter>
                <name>driverClassName</name>
                <value>com.mysql.jdbc.Driver</value>
             </parameter>
             <parameter>
                <name>url</name>
                <value>jdbc:mysql://localhost/support</value>
             </parameter>
          </ResourceParams>
       </Context>
                

Bring up the application

Start your servlet engine and bring up the application. If you have installed the web application as "support", the URL would be similar to:
   http://localhost/support/Customers.jsp
If you are using a standalone servlet engine that listens on a different port, you may need to use the port number as well:
   http://localhost:8080/support/Customers.jsp