For details, see Section 2.4. Updated information on configuring Tomcat is available at http://www.coreservlets.com/. Downloading the Software Bookmarking the Servlet and JSP APIs Tomcat bundles the documentation and links to it on the server homepage. Bookmark the version on disk so you can access it even when Tomcat is not running. Tomcat 4 Tomcat 5 Configuring the Server -
Set the JAVA_HOME variable. Have it list the base Java installation directory, not the bin subdirectory. -
Specify the server port. Edit install_dir /conf/server.xml and change the value of the port attribute of the Connector element from 8080 to 80. -
Enable servlet reloading. Edit install_dir /conf/server.xml and add the following to the top of the Service element: <DefaultContext reloadable="true"/> -
Enable the ROOT context. Uncomment the following line in install_dir /conf/server.xml : <Context path="" docBase="ROOT" debug="0"/> Some versions of Tomcat 5 are missing the trailing slash; if so, add it. -
Turn on the invoker servlet. Uncomment the invoker servlet's servlet and servlet-mapping elements in install_dir /conf/web.xml . Setting Up Your Development Environment -
Create a development directory. Develop code there; copy to the server's deployment directory for testing. -
Set your CLASSPATH . Have it include install_dir /common/lib/servlet.jar , your main development directory, and " . " (the current working directory). -
Make shortcuts to start and stop the server. In your development directory, make shortcuts to install_dir /bin/startup.bat and install_dir /bin/shutdown.bat . Double-click them to start and stop the server. Use startup.sh and shutdown.sh on Unix/Linux. Using the Default Web Application The main location is install_dir /webapps/ROOT . Create install_dir /webapps/ROOT/WEB-INF/classes if the classes directory does not already exist. You have to enable the ROOT context to use the default Web application (see the preceding section on configuring the server). Packageless Servlets Packaged Servlets Packaged Beans and Utility Classes JAR Files HTML and JSP Pages (Not In Subdirectories) HTML and JSP Pages (In Subdirectories) Using Custom Web Applications Create a Web application directory in install_dir /webapps . The directory should have a WEB-INF subdirectory, a web.xml file in WEB-INF (copy the one from ROOT ), and a WEB-INF/classes subdirectory. Instead of a regular directory, you can also use a WAR file (JAR file with file extension renamed from .jar to .war ) with this structure. In the following, we use webappName to refer to the name of the directory (or the base name of the WAR file, minus . war ). See Section 2.11 for details. Packageless Servlets -
Code Location: install_dir /webapps/ webappName /WEB-INF/classes -
Default URL: http:// host/webappName /servlet/ ServletName -
Custom URL: http:// host/webappName/AnyName ( designate / AnyName with servlet and servlet-mapping elements in web.xml ) Packaged Servlets -
Code Location: install_dir /webapps/ webappName /WEB-INF/classes/ packageName -
Default URL: http:// host/webappName /servlet/ packageName.ServletName -
Custom URL: http:// host/webappName/AnyName (designate / AnyName with servlet and servlet-mapping elements in web.xml ) Packaged Beans and Utility Classes JAR Files HTML and JSP Pages (Not In Subdirectories) HTML and JSP Pages (In Subdirectories) Viewing Autogenerated Code for JSP Pages You can view the servlet code that Tomcat generates from your JSP pages. |