![]() |
WebStringTemplates Previous ![]() ![]() ![]() |
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.
To install Tomcat V5.0 servlet server you need to:-
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)
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.
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.
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.
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
The setup of the BookDB database has three steps:-
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
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.
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.
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.
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
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.
![]() |
WebStringTemplates Previous ![]() ![]() ![]() |