Tomcat

For details, see Section 2.4. Updated information on configuring Tomcat is available at http://www.coreservlets.com/.

Downloading the Software

  • http://jakarta.apache.org/tomcat/. Click on Binaries and choose the latest release version of either Tomcat 5 (servlets 2.4 and JSP 2.0) or Tomcat 4 (servlets 2.3 and JSP 1.2). Unzip into the location of your choice, hereafter referred to as install_dir .

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
  • Servlet and JSP APIs: install_dir /webapps/tomcat-docs/servletapi/index.html

Tomcat 5
  • Servlet API: install_dir /webapps/tomcat-docs/servletapi/index.html

  • JSP API: install_dir /webapps/tomcat-docs/jspapi/index.html

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
  • Code: install_dir /webapps/ROOT/WEB-INF/classes

  • URL: http:// host /servlet/ ServletName

Packaged Servlets
  • Code: install_dir /webapps/ROOT/WEB-INF/classes/ packageName

  • URL: http:// host /servlet/ packageName.ServletName

Packaged Beans and Utility Classes
  • install_dir /webapps/ROOT/WEB-INF/classes/ packageName

JAR Files
  • install_dir /webapps/ROOT/WEB-INF/lib

HTML and JSP Pages (Not In Subdirectories)
  • Code Location: install_dir /webapps/ROOT

  • URL: http:// host/filename

HTML and JSP Pages (In Subdirectories)
  • Code Location: install_dir /webapps/ROOT/ directoryName

  • URL: http:// host/directoryName/filename

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
  • install_dir /webapps/ webappName /WEB-INF/classes/ packageName

JAR Files
  • install_dir /webapps/ webappName /WEB-INF/lib

HTML and JSP Pages (Not In Subdirectories)
  • Code Location: install_dir /webapps/ webappName

  • URL: http:// host/webappName/filename

HTML and JSP Pages (In Subdirectories)
  • Code Location: install_dir /webapps/ webappName / directoryName

  • URL: http:// host/webappName/directoryName/filename

Viewing Autogenerated Code for JSP Pages

You can view the servlet code that Tomcat generates from your JSP pages.

  • Default Web Application: install_dir /work/Standalone/localhost/_

  • Custom Web Applications: install_dir /work/Standalone/localhost/ webAppName



Core Servlets and JavaServer Pages (Vol. 1.Core Technologies)
Core Servlets and Javaserver Pages: Core Technologies, Vol. 1 (2nd Edition)
ISBN: 0130092290
EAN: 2147483647
Year: 2002
Pages: 194

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net