Back to the 2025 paper

Module II: Browser & Apache Web Server Architecture; Common Protocols

20257m

What are the features and configuration steps of the Apache Tomcat server?

Worked SolutionAI Assisted

Answer: Features and Configuration Steps of Apache Tomcat Server

1. Overview of Apache Tomcat

Apache Tomcat is an open-source web server and Java Servlet container developed by the Apache Software Foundation (ASF). It provides a pure Java HTTP web server environment in which Java code can run, implementing the Jakarta Servlet, Jakarta Server Pages (JSP), Jakarta Expression Language (EL), and WebSocket technologies.


2. Key Features of Apache Tomcat

  1. Servlet & JSP Container: Implements modern Servlet and JSP specifications through its internal engines:
    • Catalina: The core Servlet engine.
    • Jasper: The JSP engine that compiles JSPs into Servlets.
    • Coyote: The HTTP connector supporting HTTP/1.1, HTTP/2, and AJP protocols.
  2. Lightweight & Fast: Highly optimized for Java enterprise web applications with low resource overhead.
  3. Cross-Platform: Pure Java implementation that runs seamlessly on Windows, Linux, macOS, and Unix.
  4. JNDI Resource Management: Supports enterprise connection pooling (e.g., MySQL, Oracle database DataSources).
  5. Clustering & Session Replication: Supports high availability and load balancing across multiple Tomcat instances.
  6. Embeddable: Can be embedded directly inside Java applications (commonly used in Spring Boot).

3. Directory Structure of Tomcat

Directory Description
/bin Startup, shutdown, and control scripts (startup.bat/startup.sh, catalina.sh).
/conf Core XML configuration files (server.xml, web.xml, tomcat-users.xml, context.xml).
/lib Shared JAR libraries and JDBC drivers.
/logs Server log files (catalina.out, localhost_access_log).
/webapps Directory where web applications (.war files or unpacked directories) are deployed.
/work Temporary work directory where compiled JSP servlets and temporary files are stored.

4. Configuration Steps for Apache Tomcat

Step 1: Install Prerequisites & Set Environment Variables

Tomcat requires Java Development Kit (JDK 8+). Set environment variables in the OS:

  • JAVA_HOME: Path to JDK directory (e.g., C:\Program Files\Java\jdk-17 or /usr/lib/jvm/java-17-openjdk).
  • CATALINA_HOME: Path to the root Tomcat installation directory.
  • Add %CATALINA_HOME%\bin (or $CATALINA_HOME/bin) to the system PATH.

Step 2: Configuring Server Ports (conf/server.xml)

To change the default HTTP port (from 8080 to 80 or custom port):

<!-- conf/server.xml -->
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443"
           maxThreads="200" />

Step 3: Configuring Admin Users and Roles (conf/tomcat-users.xml)

To grant access to the Tomcat Web Application Manager GUI (http://localhost:8080/manager/html):

<!-- conf/tomcat-users.xml -->
<tomcat-users>
    <role rolename="manager-gui"/>
    <role rolename="admin-gui"/>
    <user username="admin" password="SecretPassword123" roles="manager-gui,admin-gui"/>
</tomcat-users>

Step 4: Global Web Application Settings (conf/web.xml)

Configures default MIME types, default welcome files (index.html, index.jsp), and global session timeouts:

<!-- conf/web.xml -->
<session-config>
    <session-timeout>30</session-timeout> <!-- In minutes -->
</session-config>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Step 5: Application Deployment & Server Management

  1. Deploying Applications:
    • Copy your .war archive (e.g., myapp.war) directly into the $CATALINA_HOME/webapps/ folder.
    • Tomcat automatically unpacks and deploys the application.
  2. Starting the Server:
    • On Windows: Run bin\startup.bat
    • On Linux/macOS: Run bin/startup.sh
  3. Verifying Installation:
    • Open browser at http://localhost:8080.
  4. Stopping the Server:
    • Run bin\shutdown.bat or bin/shutdown.sh.

Similar questions