
This is a short tutorial on creating a new application on Tomcat.
It assumes the site is hosted with Metawerx
, but will work elsewhere as long as you can find your webapps folder, have the Tomcat Manager installed, or can manually reset the JVM if necessary.
First, locate your webapps folder, this will be referred to as <tomcat> below
Create a folder under the webapps/tomcat folder (eg: /private-cgi-bin/tomcat/MyNewApp)
Create a WEB-INF folder in the new folder (eg: /private-cgi-bin/tomcat/MyNewApp/WEB-INF)
Your application folder structure should now look like this:
<tomcat>/MyNewApp/ <tomcat>/MyNewApp/WEB-INF/
Create a new file in WEB-INF called web.xml, containing the following:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>My First App</display-name>
<description>This is my first application</description>
</web-app>
Your application structure should now look like this:
<tomcat>/MyNewApp/ <tomcat>/MyNewApp/WEB-INF/ <tomcat>/MyNewApp/WEB-INF/web.xml
As soon as Tomcat notices the */WEB-INF/web.xml file inside the tomcat folder, it will deploy the application, and it will appear in the Tomcat Manager using the name from the <display-name> tag above.
Create a file called /tomcat/MyNewApp/index.htm using the following content:
<h1>My First App</h1> <p>This is an application running on Tomcat</p>
Your application structure should now look like this:
<tomcat>/MyNewApp/ <tomcat>/MyNewApp/index.htm <tomcat>/MyNewApp/WEB-INF/ <tomcat>/MyNewApp/WEB-INF/web.xml
That's all there is to it! The application should have started automatically. This can be checked in the Tomcat Manager.
To write some JSP, try renaming index.htm as index.jsp, or make a new file, then add some JSP code to it.
For Java Servlets, you will need to add some information in the web.xml file. This is covered in more detail at web.xml.