Advertisment

Tomcat 4 on PCQLinux 7.1

author-image
PCQ Bureau
New Update

In the previous issues of PCQuest we have discussed Tomcat (version 3) application server and explained how to set it up and customize it on Linux. Tomcat is a JSP (Java Server Pages) and Servlet engine, which can be used to deploy Java-based Web applications. The latest stable release of Tomcat–version 4.0.4–uses (or implements) Servlet 2.3 and JSP 1.2 specifications. 

Advertisment

As with Tomcat 3 (see Tomcat on Linux, page 105, PCQuest April 2001), Tomcat 4 can be set up as a standalone server as well as made to work in conjunction with Apache Web server. In the latter case, while Apache serves content like HTML pages, images, applets, and other non-JSP and non-Servlet contents, requests for JSP and Servlets are handed over to Tomcat. However, even for the latter setup, Tomcat must be first up and running as a standalone application server. 

Tomcat can be used to run JSP and Java Servlets-based Web applications. What’s more, it can even integrate easily with Apache Web server

Standalone Tomcat

Setting this up is as easy as before–as with Tomcat 3. First, JDK (Java Development Kit) for Linux must be installed. The latest version can be downloaded from http://java.sun.com. We used JDK 1.4.0, which can be found on September 2001 PCQuest CD. 

Advertisment

We have given out the Tomcat 4 archive file–jakarta-tomcat-4.0.4.tar.gz–in the directory system/cdrom/linux on this month’s CD. Copy this file to /opt directory and issue the following command to extract the archive.

tar —zxvf jakarta-tomcat-4.0.4.tar.gz

This will produce a directory named jakarta-tomcat-4.0.4 within /opt. Rename this directory to “tomcat” as:

Advertisment

mv /opt/jakarta-tomcat-4.0.4 /opt/tomcat

Next, set an environment variable named JAVA_HOME that will point to the directory where JDK is installed. In our case, JDK is installed by default in the directory /usr/java/j2sdk1.4.0_01. Hence, we set JAVA_HOME by issuing the following command at the Linux console.

export JAVA_HOME=/usr/java/j2sdk1.4.0_01

Advertisment

Append the above line to a file named profile found in the /etc directory. This will set the variable automatically on subsequent reboots. 

All done. Now run Tomcat by issuing the following command.

/opt/tomcat/bin/startup.sh

Advertisment

If things have gone fine, you should be able to see the page (as shown in the screenshot on the following page) when you key in the URL–http://127.0.0.1:8080/–in a Web browser (Netscape or Konqueror) on the same Linux machine. 

Here 8080 is the port at which Tomcat runs or listens to. Tomcat installs with a couple of sample Web applications (JSPs and Servlets). These can be found in the directory /opt/tomcat/webapps/ examples. One such application is a number guessing JSP app. To see it working, key in the following URL in the Web browser.

http://127.0.0.1:8080/examples/jsp/num/numguess.jsp

Advertisment

Tomcat with Apache

With Tomcat 3 we used a module named mod_jserv.so to set up Apache Web server to work with Tomcat. With Tomcat 4, we use a new module called mod_webapp.so. The functionality of these modules is that they forward the request made to Web server (Apache)–for JSP and Servlets–to the Web container (Tomcat). For this reason, these modules are also called connectors. As you will see, mod_webapp.so is easier to setup as opposed to
mode_jserv.so. 

From the directory system/ cdrom/linux, copy the file webapp-module-1.0-tc40-linux-glibc2.2.tar.gz to /opt directory. Extract the archive as:

tar —zxvf webapp-module-1.0-tc40-linux-glibc2.2.tar.gz 

Advertisment

This will produce a directory named webapp-module-1.0-tc40 within /opt. Copy the file mod_webapp.so found in this directory to
/etc/httpd/modules. 

Next, open the file httpd.conf, found in /etc/httpd/conf directory, in a Linux text editor and append the following lines to it.

LoadModule webapp_ module modules/mod _webapp.so

AddModule mod_webapp.c

WebAppConnection conn warp localhost:8008

To see the sample Web applications–in the examples directory–working, you need to add the following line to httpd.

conf after the above-mentioned lines.

WebAppDeploy examples conn /examples

Save httpd.conf file and restart apache Web server as:

/etc/rc.d/init.d/httpd restart

In case you see an error–“invalid virtual host name”–then you need to set the ServerName directive to Apache. For this, add the following line in httpd.conf file.

ServerName www.pcqlabs.net

You can replace pcqlabs.net with any name of your choice. To see the number guess JSP application working, key in the following URL in the browser.

http://127.0.0.1/examples/jsp/num/numguess.jsp

Note that this time we haven’t mentioned the port number as 8080. Hence the request will go to the default port–port 80–at which Apache Web server is running. Apache gracefully hands over the request–being a 

request for a JSP file–to Tomcat. And you see the game executing. 

Next month we will talk about the configuration of Tomcat 4 and how you can deploy your own Web applications. 

Shekhar Govindarajan

Advertisment

Stay connected with us through our social media channels for the latest updates and news!

Follow us: