Developing Web App Using Tomcat


Jakara Tomcat is the servlet container that is used in the official Reference Implementation for the Servlet and JSP technologies. The latest version of Tomcat (Tomcat 5.x) implements the Servlet 2.4 and JSP 2.0 specifications, and includes many additional features that make it a useful platform for developing and deploying web applications and web services.

Given the course web app server (which will use Tomcat too) has not been set up yet, you could install Tomcat in your local machine. Even running in your machine, Tomcat could act as a server, manipulating requests you sent, and composing responses for you. 

Install Tomcat

To use Tomcat, you have to download and install several software:

1. JDK platform to compile your servlets, java classes or JSP pages. We recommend JDK 5.0  

     You could download appropriate versions of JDK from http://java.sun.com/j2se/.กก

2. Tomcat. You can select downloading binary or source code distribution from http://jakarta.apache.org/. The only 

  tricky thing to install Tomcat is to be careful when configure several environment variables. You can get      

  instructions for Tomcat 5.5 is available at here

3. Apache Ant (Recommended). Ant is a useful project building tool, which is in some sense like make. Its binary   

   distribution is available from here.

Have you installed Tomcat, you can launch Monitor Tomcat tool, and start the web service, Then open a web browser, and input in the address bar the URL http://localhost:8080, then you can view Tomcat documentation or start using Tomcat.

Develop web application with Tomcat

1. Create your web application directory in a standard layout. In $CATALINA/webapps, you should create a diretory for your web application, e.g. MyApp. Then your application directory will be $CATALINA/webapps/MyApp. Here '$CATALINA/' refers to the directory into which you install the Tomcat in your machine. Then in your application, all file paths used in your *.html, *.jsp files will be resolved relative to this path. Later on, once you deploy your application into Tomcat, you could use URL http://localhost:8080/MyApp/XXX to access the XXX file in your application directory.

The standard layout of your application directory should be:

Once you create such an application directory, you should create and customize a build.xml file, which is a script used by Ant about how to build your project, to describe how to build your project. There is a simple example of build.xml in Tomcat documentation, which explains the exact structure and meaning of such a file. To review it, just start up Tomcat, and visit URL http://localhost:8080/tomcat-docs/appdev/build.xml.txt. You could also start defining yourselves' from this scratch.

Here I won't go into details about developing your application, which is in generic a Coding-Testing-Refining process. Once you finish this process, you could deploy your application into Tomcat. There are two ways to do this: the simpler one is restarting Tomcat service, which will make Tomcat deploy your application automatically; Or if you wanna deploy and undeploy applications during the running time of Tomcat service, you can use the Tomcat Manager application, a default application implemented by Tomcat, to do this. But in the later approach you are required to have a manager role. To acquire this, open $CATALINA/conf/tomcat-users.xml in some editor, add such a statement <user username="XXX" password="YYY" roles="manager"/> into it, save the file, and restart Tomcat service. (Here replace "XXX" and "YYY" with what you prefer to use for the manager user). 

I prepared a simple sample web application, visit here for the source code. For more details about how to develop with Tomcat, just start up the Tomcat service, and visit the URL http://localhost:8080/tomcat-docs/index.html.

กก

กก

                             Go Back To TA Information Page                                        

กก


Course Webpage | JSP | Servlet | Apache Ant | Apache Jakarta Tomcat | FAQ | Contact Us