You are on page 1of 13

Tomcat

Celsina Bignoli
bignolic@smccd.net
History of Tomcat
Tomcat is the result of the integration of two groups of
developers.
JServ, an open source implementation of the Servlet
specification.
Suns own servlet engine.
The focus of the two groups was different:
JServ concentrated on performance
Suns implementation was more concerned with adherence to
specification.
Sun donated the code to Apache Software Foundation.
A group was formed named Jakarta - that was given a
charter of merging the implementations
Tomcat was born

Tomcat Requirements
Strict adherence to Suns JSP/Servlet
specification
Interoperability
Modifiability
Performance
Scalability
High-availability
Security
Architecture
Architecture
Server: Server represents the entire Tomcat server. One server per
JVM.
Service: Service component creates the connectors and associates
the engine with this group of connectors.
Connector: Connectors are components that implement the socket
listeners. They connect web applications to clients. This component
provides flexibility to the Tomcat architecture. It allows the Tomcat
servlet engine to integrate with many different types of web servers
such as Apache, IIS etc.
Engine: Engine is the top level container. It examines the request
and routes the request to the appropriate virtual host.
Host: This allows multiple servers to be configured on the same
physical machine and be identified by separate IP addresses.
Context: This represents a single web application
Tomcat Installation and
Configuration
Install JDK1.5
Download the Jakarta Tomcat software
Set the JAVA_HOME variable
Change port from 8080 to 80 (optional)
Set the CATALINA_HOME variable
Changing port to 80
configure Tomcat to run on the default HTTP port (80)
instead of the out-of-the-box port of 8080.
Making this change lets you use URLs of the form
http://localhost/blah instead of http://localhost:8080/blah
Some versions of Windows XP automatically start IIS on
port 80.
So, if you use XP you may need to disable IIS (see the
Administrative Tools section of the Control Panel).
To change the port, edit install_dir/conf/server.xml and
change the port attribute of the Connector element from
8080 to 80
<Connector port="80" ...
maxThreads="150" minSpareThreads="25" ...
Setting CATALINA_HOME Variable
set the CATALINA_HOME environment
variable to refer to the top-level directory
of the Apache Tomcat installation (e.g.,
C:\jakarta-tomcat-5.5.15).
This variable identifies the Tomcat
installation directory to the server.
Testing the Server
Involves two steps:
Verifying that the server can even start
Checking that you can access your own
HTML and JSP pages
use the default Web application.
put HTML and JSP pages in
install_dir/webapps/ROOT or
install_dir/webapps/ROOT/somePath and
access them with http://localhost/filename or
http://localhost/somePath/filename.
Setting the Development
Environment
Define a working directory in which to
place the servlets and JSP pages that you
develop
The development directory should NOT
reside in the Tomcat deployment directory

Making Shortcuts
to Start and Stop the Server
place shortcuts to the server startup and
shutdown scripts inside the main
development directory or on the desktop.
Go to install_dir/bin, right-click on startup.bat,
and select Copy.
go to your development directory, right-click in
the window, and select Paste Shortcut (not
just Paste).
Repeat the process for
install_dir/bin/shutdown.bat.
Setting CLASSPATH
Since servlets and JSP are not part of the Java
2 platform, standard edition, you have to identify
the servlet classes to the compiler.
The server already knows about the servlet
classes, but the compiler (i.e., javac) you use for
development probably doesn't.
Include the following jar file in the CLASSPATH
install_dir/common/lib/servlet-api.jar
install_dir/common/lib/jsp-api.jar
Alternatively you can put the above jar files in
java_dir/lib/ext
Compiling and Testing Simple
Servlets
to verify the environment is all set compile and
run some simple Servlet, i.e. HelloServlet.java
the location for servlets in the default Web
application is:
install_dir/webapps/ROOT/WEB-INF/classes
Once you compile HelloServlet.java, put
HelloServlet.class in:
install_dir/webapps/ROOT/WEB-INF/classes
After compiling the code, access the servlet with
the URL:
http://localhost/servlet/HelloServlet