Forward Logo (image)       WebStringTemplates
      Previous Back Back Back Next

WebStringTemplates for the Programmer

Running the Server Examples

To run the server examples you need a running servlet server and database. I used Tomcat V5.0 and MySQL database and the xml configuration files are setup to work with these. If you are using another server and database you may need to edit the web server configuration files to suit your setup. The first three examples only need the servlet server. The later examples need the database as well as the server.

This page covers:-

If you already have Tomcat V5.0 and MySQL installed, skip to Setting up the MySQL BookDB Database below.

Installing the Tomcat V5.0 Servlet Server

To install Tomcat V5.0 servlet server you need to:-

  1. Download the Server
  2. Run the installation
  3. Check the installation

Download the Server

Download tomcat from http://jakarta.apache.org/tomcat/
Choose download binaries and towards the bottom of the page you will find downloads for Tomcat, I used V5.0.14 (windows exe)

Run the installation

See http://jakarta.apache.org/tomcat/tomcat-5.0-doc/setup.html
for installation details. The window.exe is self installing, but first set the JAVA_HOME environmental variable to your Java JSK V1.4.2 install directory.

I chose the Normal installation and accepted the default install location of
C:\Program Files\Apache Software Foundation\Tomcat 5.0

I accepted the default Connector port of 8080 and admin user name of admin, and chose a very insecure password of admin. My Java SDK was installed in
C:\j2sdk1.4.2
and JAVA_HOME was set so the install found it. Tomcat started when the installation completed.

Check the Installation

To check that Tomcat is up and running, open a web browser and enter the following URL
http://localhost:8080
This should show the Tomcat home page. If it does not refer to the http://jakarta.apache.org/tomcat/ web site for further information on possible problems.

Installing RunWST in the Servlet Server

To intall the RunWST jar file copy it from the directory where you unzipped to files to the
Tomcat 5.0/common/lib
sub-directory. That is it. The RunWST is installed for the web server. If you are using another web server other than Tomcat, you will need to find out where to put supporting jar files and put the RunWST jar in that directory.

Installing MySQL

To install MySQL, download it from
http://www.mysql.com/downloads/mysql-4.0.html

I used the window version 4.0.16 zip. Unzip it and run the setup.exe, you need administrator access to do this. I accepted the default dir of
C:\mysql
and the typical installation and rebooted after it finished. When the quick start dialog box came up I choose
username: bookstore
password: webstringtemplates
but see below for setting up this user with the necessary privileges.

By default the password for root is blank. I left it blank for testing but you should set it for a production environment

Setting up the MySQL BookDB Database

The setup of the BookDB database has three steps:-

  1. Add a new user
  2. Create and test the database
  3. Install the MySQL JDBC driver for Tomcat

Adding a New User

The server examples connect to the database using username: bookstore and password: webstringtemplates. To add this user to MySQL and grant the necessary privileges, open a command prompt, change directory to the mysql/bin dir and run the command
mysql --user=root mysql

Then at the mysql prompt enter the following mysql commands
mysql> GRANT ALL PRIVILEGES ON *.* TO bookstore@localhost IDENTIFIED BY 'webstringtemplates' WITH GRANT OPTION;
mysql>quit

Creating and testing the BookDB

To create the BookDB, copy the books.sql file from the serverExamples\mysql_data sub-directory to the mysql/bin directory and from the mysql/bin directory run the command
mysql -u root <books.sql

Check that user bookstore can access this new table, from the mysql/bin directory run the command
mysql -u bookstore -p bookdb
when prompted enter the password: webstringtemplates
Enter password: ******************
and then from the mysql shell run the following mysql command to display the contents of the books table of BookDB
mysql> select * from books;
This should show the contents of the books table.

If you have any problems you will have to work through the mysql manual to resolve them.

Installing the MySQL JDBC driver for Tomcat

Download the driver from
http://www.mysql.com/downloads/api-jdbc-stable.html
and extract the
mysql-connector-java-3.0.9-stable-bin.jar
to the
Tomcat 5.0/common/lib
sub-directory. That is it. The driver is installed.

Installing and running the Server Examples

Each server example comes with a pre-built WAR file in the serverExamples\preparedWarFiles sub-directory.

To install all the examples, stop the Tomcat server (there is a shutdown batch file in the Tomcat 5.0/bin sub-directory), copy the war files from serverExamples\preparedWarFiles to the Tomcat 5.0/webapps sub-directory and re-start the Tomcat server.

To run the examples open a web browser and enter the url
http://localhost:8080/bookstore1Servlet
for the first example, http://localhost:8080/bookstore2Servlet for the bookstore2Servlet example and so on.

Most of the examples are not full applications, but just a single page to illustrate what is needed, so links shown on the output pages usually don't go anywhere.

Re-compiling the Server Examples

Each server example has a build.xml file in its directory. You need to have Ant installed to use this build file. You can download Ant from http://ant.apache.org/ See the Ant manual for installation instructions.

You need to modify each build file to tell it where your installation of Tomcat is. At the top of each build.xml file you will find the line

<property name="catalina.home" value="/Program Files/Apache Software Foundation/Tomcat 5.0"/> <!-- UPDATE THIS! -->

Update the value to reflect the install directory of Tomcat. The directory shown here is the default directory for the Windows installation. Once Ant is installed and running, and the build file has been updated, you can re-compile and re-install a server example by

  1. Stopping the Tomcat Server
  2. Opening a command prompt in the server example directory (for example serverExample/bookstore1Servlet) and typing the command
    ant
    This will run the default task in the build.xml file which re-compiles the java code, creates a war file and copies it to the Tomcat 5.0/webapps directory.
  3. Restarting the Tomcat Server.



Forward Logo (image)       WebStringTemplates
      Previous Back Back Back Next

Contact Forward Computing and Control by
©Copyright 2004 Forward Computing and Control Pty. Ltd. ACN 003 669 994