CIS-2450 Lab #12: Tomcat

Reading: ...

In this lab you will experiment with the Tomcat application server.

Part 1: Setting up Tomcat

Proceed as follows:

  1. Download and unpack Tomcat. If you are a Windows user, you can download the Windows binary from the Tomcat Home Page. Be sure to use version 10.1.33 (not version 11.0.1). If you are a Linux user, you can likely install a recent enough version of Tomcat (10.x.y) from your distribution's package manager. If you are a macOS user, install Tomcat via Homebrew.

    On Windows, I suggest unpacking Tomcat in your home directory C:\Users\<username>. The zip archive contains a top-level folder named apache-tomcat-10.1.33 into which it unpacks the files.

  2. Edit the file conf/tomcat-users.xml (path relative to the root of the Tomcat distribution). About 3/4 the way down the file, you will find the definitions of users admin and robot. The definitions are commented out. Uncomment those definitions and set the passwords to something reasonable (but don't use one of your "real" passwords).

  3. Start Tomcat by executing the startup script in the bin folder. On Windows this will pop up another console window showing you to server log messages. Don't be alarmed if you see many INFO messages.

  4. Go to http://localhost:8080 in a web browser to see the Tomcat welcome page. Notice that your Tomcat serves the documentation and configuration links. An application server can play the role of a simple web server.

  5. Click on the "Manager App" button (upper right) and log in using the administrative username and password you previously configured. Look around!

Part 2: Demonstrate a Web Application

Proceed as follows:

  1. Clone my WebDev sample project from GitHub. In the repository you will find a Tomcat/demo folder containing a demonstration application. Using a command shell, change to that directory.

  2. Execute mvnw package to compile the sample and create a "web archive" (WAR) file from the compiled artifacts. The WAR file is left in target/demo-1.0-SNAPSHOT.war

  3. Using Tomcat's administrative interface ("Manager App"), deploy the WAR file you just created by filling in the fields in the "Deploy" section of the "Tomcat Web Application Manager" page. You can use the simplified dialog where you just specify the WAR file and let Tomcat set everything else up for you.

    To see the deployed web application, go to http://localhost:8080/demo-1.0-SNAPSHOT. In the file system where Tomcat is running, look in the webapps folder under Tomcat's installation folder. You should see that the WAR file has been copied there and then expanded into a folder of the same name.

  4. Make a minor modification to the servlet and rebuild the WAR file. Using Tomcat's administrative interface, "undeploy" the old version of the demo web application and deploy your new version in its place. Verify that the new version works.

Part 3: Shutdown Tomcat

Proceed as follows:

  1. Stop Tomcat by executing the shutdown script in the bin folder.

  2. Go to the log folder in Tomcat's installation folder and inspect the contents of the localhost.YYYY-MM-DD.log file. You should see the log messages output by your application there.

Submission

Zip together your modified version of the servlet class and the log file showing the messages it logs, and submit the archive to Canvas.


Last Revised: 2024-12-06
© Copyright 2024 by Peter Chapin <peter.chapin@vermontstate.edu>