Tomcat
Ramiro Lago Bagüés (Abril 2007)
¿Qué es Tomcat?
Es el servidor web y de aplicaciones del proyecto Yakarta, decimos que es servidor web
ya que gestiona solicitudes y respuestas Http (incluye el servidor Apache) gracias a sus
conectores Http; además es servidor de aplicaciones o contenedor de Servlets/JSP (Catalina).
Para una explicación de lo que es un servidor de aplicaciones ver:Capítulo de JEE -
Arquitectura.
Para una introducción a Tomcat podemos ver Wikipedia
Instalación
Lo primero es la descarga en
El sitio de la Apache Software Foundation. El ejecutable incluye un wizard que facilita
bastante la instalación:

Aspectos a tener en cuenta:
- A menos que se esté utilizando previamente el puerto 8080 por otra aplicación,
resulta aconsejable dejar este puerto para Tomcat (es el puerto por defecto para el servidor web).
- Se le debe indicar el lugar donde se encuentra nuestro JRE (en la versión 5.5 de Tomcat,
en versiones anteriores requería un JDK).
- Resulta aconsejable instalarlo como un servicio que será arrancado por el sistema
operativo al iniciarse.
Si todo ha ido bien debemos poder ver la siguiente página de bienvenida:

En el manager podremos ver la lista de aplicaciones. Por defecto se incluyen aplicaciones
de ejemplo, el manager, etc. Para cada una de ellas podemos pararla, iniciarla, etc. Ojo: si no
es un usuario experimentado tenga cuidado con cualquier botón del tipo "Replegar" o "Eliminar".

Además es conveniente comprobar que se ha instalado como un servicio del sistema:

Conviene echar un vistazo a la estructura de directorios creada por Tomcat:

Directorios clave que instala Tomcat:
- /bin - El nucleo de Tomcat. Necesario para iniciar, parar, etc.
- /conf - Archivos de configuración. El más importante es server.xml, que es el
descriptor del servidor Tomcat.
- /logs - Archivos de log.
- /webapps - Para las aplicaciones que vienen con Tomcat. Las aplicaciones
que realicemos nosotros podremos ponerlas en esta ruta o en otra.
server.xml
Es el descriptor de la configuración del servidor. Las características más importantes
son definición de puertos de invocación, de parada y conectores, así como describir los
contextos de aplicación.
Sólo vamos a apuntar unas cuantas de las principales características:
....
<Context
displayName="public_html: proactiva-calidad.com local"
className="org.apache.catalina.core.StandardContext"
cookies="true"
crossContext="true"
docBase="C:\web\public_html"
path="/public_html"
reloadable="true"
wrapperClass="org.apache.catalina.core.StandardWrapper"
cachingAllowed="true"
swallowOutput="false"
useNaming="true"
workDir="work\Standalone\localhost\public_html">
....
</Context>
</Host>
</Engine>
</Service>
</Server>
Observe que el contexto de aplicación debe aparecer dentro del apartado "host". En nuestro
caso lo hemos puesto al final de "host".
Hemos marcado con negrita los más importantes de cara a la instalación.
Algunos de los atributos de las aplicaciones:
- className:
Java class name of the implementation to use.
This class must implement the org.apache.catalina.Context interface.
If not specified, the standard value (defined below) will be used.
- cookies:
Por defecto true
- crossContext:
True si quieres usar ServletContext.getContext() para redirigir (request dispatcher) a otra aplicación de este host virtual.
En entornos de fuerte seguridad poner false (por defecto); hace que getContext() devuelve null.
- docBase:
Obligatorio. Puede ser una ruta absoluta o relativa al directorio del Host
- path:
The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing.
All of the context paths within a particular Host must be unique.
- reloadable:
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes,
and automatically reload the web application if a change is detected. This feature is very useful during application development,
but it requires significant runtime overhead and is not recommended for use on deployed production applications.
That's why the default setting for this attribute is false. You can use the Manager web application, however,
to trigger reloads of deployed applications on demand.
- wrapperClass:
va class name of the org.apache.catalina.Wrapper implementation class that will be used for servlets managed by this Context.
If not specified, a standard default value will be used.
- cachingAllowed:
If the value of this flag is true, the cache for static resources will be used. If not specified, the default value of the flag is true.
- allowLinking:
If the value of this flag is true, symlinks will be allowed inside the web application, pointing to resources outside the web application base path.
If not specified, the default value of the flag is false.
NOTE: This flag MUST NOT be set to true on the Windows platform (or any other OS which does not have a case sensitive filesystem),
as it will disable case sensitivity checks, allowing JSP source code disclosure, among other security problems.
- swallowOutput:
If the value of this flag is true, the bytes output to System.out and System.err by the web application will be redirected to the web application logger.
If not specified, the default value of the flag is false.
- useNaming:
Set to true (the default) to have Catalina enable a JNDI InitialContext for this web application that is compatible with Java2 Enterprise Edition
(J2EE) platform conventions.
- workDir:
Pathname to a scratch directory to be provided by this Context for temporary read-write use by servlets within the associated web application.
This directory will be made visible to servlets in the web application by a servlet context attribute
(of type java.io.File) named javax.servlet.context.tempdir as described in the Servlet Specification.
If not specified, a suitable directory underneath $CATALINA_HOME/work will be provided.
Volver al índice