2009-09-26

Tomcat configuration file - web.xml

Tomcat configuration file (web.xml) is using XML pattern, which the global configuration file is within tomcat\conf directory, and individual configuration file is within tomcat\wepapps\webdir\WEB-INF directory. User can always refer to the global configuration file as a sample to set the individual configuration file. The parent node of web.xml is <web-app> and below is the common nodes that can be used:

  1. Description for the web application.
    <description>
    Description for Web Application
    </description>
  2. Map the servlet to associate class and URL pattern.
    <servlet>
    <servlet-name>servlet name</servlet-name>
    <servlet-class>class name</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>servlet name</servlet-name>
    <url-pattern>url pattern</url-pattern>
    </servlet-mapping>

  3. Map the taglib to associate TLD files.
    <taglib>
    <taglib-uri>
    http://www.gnokproject.com/taglibs/taglib-v1.0
    </taglib-uri>
    <taglib-location>
    /WEB-INF/jsp/taglib.tld
    </taglib-location>
    </taglib>
  4. Map extension to associate mime type.
    <mime-mapping>
    <extension>html</extension>
    <mime-type>text/html</mime-type>
    </mime-mapping>

  5. Session timeout.
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
  6. First file to be accessed.
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>

2009-09-25

WEBAPPS directory structure

WEPAPPS is the directory that keep all the JSP files and JAVA files, and the place where people will get into when they are accessing Apache Tomcat. Inside WEBAPPS directory, each sub directory represents a sub directory in the URL, for example a sub directory named subdir represents www.gnokproject.com/subdir. Except for one directory called ROOT which represents the root directory www.gnokproject.com.

Inside each sub directory will have a directory called WEB-INF which contain:

  1. classes directory: keep the JAVA source files which will be auto compiled by Tomcat when the classes are needed.
  2. jsp directory: keep the TLD files or the tag library files.
  3. lib directory: keep the JAR files.
  4. web.xml: configuration files of that particular directory.

2009-09-23

Apache Tomcat directory structure

Tomcat's directory structure:

bin
Keep all execution files, for example startup.bat and shutdown.bat.
conf
Keep all the common configuration files, such as server.xml.
lib (in 6.0, or common, server, shared in 5.5)
Keep all the common classes and jar files that will be shared by all JAVA and JSP files in webapp.
logs
Keep all the log files.
webapps
Keep all the JSP files, where you normally spend most of the time here.
temp
Temporary directory.
work
Keep the caches compiled from JSP and JAVA files from wepapp.

Change Tomcat port from 8080 to 80

To change Apache Tomcat port from 8080 to 80 (so that developer or user doesn't need to type :8080 at the back of the URL):

  1. Edit TOMCAT_DIR\conf\server.xml.
  2. Look for line similar to below (the keyword is connector and 8080):
  3. Just change 8080 to 80 and restart Tomcat.

Setup Apache Tomcat to host JSP

JSP (Java Server Page) is Java based web programming language. Similar to ASP and ASPX (and different from PHP), JSP can be compiled into classes before used in the pages. To start coding in JSP, we need to setup Apache Tomcat first. Follow the steps below:

  1. Download JDK (Java Development Kit) from Java Website. Any version will do, but if you don't have any idea, just download and install the newest version.
  2. Download Apache Tomcat from Apache Tomcat Website. Currently there are versions 4.1, 5.5 and 6.0. Either version will do, or just pick the newest version.
  3. There are 2 types of Tomcat installation file, zip and windows installer. Either type is fine, or just download the zip version. Extract the zip file to any directory.
  4. Go to the Tomcat directory that you extracted (or installed), go to bin folder and edit the startup.bat file.
  5. Add the JAVA_HOME environment variable at the beginning of the startup.bat file (after @echo off)
    set java_home=C:\Program Files\Java\jdk1.6.0_16

  6. Then you may double click the startup.bat to start Tomcat. If a command terminal is shown without disappearing, it properly means OK.
  7. To test it out, open a browser and go to localhost:8080. If something come out (not the error message of course), that means you have setup Tomcat successfully.