Book Image

Apache Tomcat 7 Essentials

By : Tanuj Khare
2 (1)
Book Image

Apache Tomcat 7 Essentials

2 (1)
By: Tanuj Khare

Overview of this book

Apache Tomcat (or simply Tomcat) is an open source servlet container developed by the Apache Software Foundation (ASF). The latest major stable release, Apache Tomcat version 7 implements the Servlet 3 and JavaServer Pages 2 specifications from the Java Community Process, and includes many additional features that make it a useful platform for developing and deploying web applications and web services.Apache Tomcat 7 Essentials follows a practical approach to teach installing, configuring, and maintaining Tomcat. It helps you to understand the middle architecture for hosting multiple websites and also provides the confidence to implement middleware support. It imparts to you the capacity to resolve migration issues and also provides regular maintenance solutions. This is the first and only book to cover upgrading to Tomcat 7 from previous versions.The journey of the reader starts at the beginner level and ends at the expert level. The content is designed in such a way that it balances the theory and practical approach for understanding concepts related to handling middle ware and web issues.In this book, you will go through a three-phase life cycle. The first cycle consists of installation, configuration of Tomcat 7 on different OS, and other configurations related to JDBC, port, deployment etc. The second phase deals with the building of enterprise application setup and high availability architecture (clustering load balancing). The third and critical phase will teach you to handle critical issues, performance tuning, and best practices for various environment stacks like dev/QA/stage/production.This book gives you a wider vision of using Tomcat 7 in web technologies and the skill to optimize their performance using Apache Tomcat 7.
Table of Contents (18 chapters)
Apache Tomcat 7 Essentials
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Chapter 1. Installation of Tomcat 7

Apache Tomcat is an open source Java-based web and servlet container, which is used to host Java-based applications. It was first developed for Jakarta Tomcat. Due to an increase in demand, it was later hosted as a separate project called Apache Tomcat, which is supported by The Apache Software Foundation. It was initially developed by James Duncan Davidson, a software architect at Sun Microsystems. He later helped make this project open source and played a key role in donating this project from Sun Microsystems to The Apache Software Foundation. Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run.

Apache Tomcat version 7.0 implements the Servlet 3.0 and Java Server Pages 2.2 specifications from the Java Community Process. It includes many additional features that makes it a useful platform for developing and deploying web applications and web services.

In this chapter, we will discuss the following topics:

  • Introduction to Tomcat 7

  • Features of Tomcat 7

  • Installation of Tomcat

    • Prerequisites for Tomcat 7 installation

    • Installation on Linux and Windows operating systems

  • Common areas of troubleshooting during installation

History of Tomcat

Tomcat was first introduced to the open source group in 1999 and its first version was released with 3.0.x version. Since then, it has been greatly supported by the open source community and widely accepted in the IT industry. In the current scenario, Tomcat is running in production environments, as well as being used for mission-critical projects in various industries. The following mentioned details give us a quick history of the versions.

Over the 12 years of of its successful journey, Tomcat has reached various states and given the IT industry various releases. Tomcat road maps outlined with their stable releases are mentioned as follows:

Version

Release Date

Description

3.0.x. (initial release)

1999

Merger of donated Sun Java Web Server code and ASF, and implements Servlet 2.2 and JSP 1.1 specifications.

3.3.2

March 9, 2004

Latest 3.x release.

4.1.40

June 25, 2009

Latest 4.x release.

5.5.32

February 1, 2011

Latest 5.x release.

6.0.32

February 3, 2011

Latest 6.x release.

7.0.0 beta

June 29, 2010

First Apache Tomcat release to support Servlet 3.0, JSP 2.2, and EL 2.2 specifications.

7.0.11

March 11, 2011

Fourth stable version.

7.0.12

April 6, 2011

Current stable version.

Note

For more information on version changes, release, and comparison, visit http://en.wikipedia.org/wiki/Apache_Tomcat and http://wiki.apache.org/tomcat/FrontPage.

Tomcat support matrix

Apache Tomcat can be classified based on different components, such as the JDK version, enhancement, stability, and so on. Let's take a real time example, where you want to take a decision on which Apache Tomcat version to deploy for an application. For example, if an application is using Servlet 2.4 and JSP 2.0, then we should always go for the 5.x version. In reality, it's a difficult job to find out which version of Tomcat we should use to utilize the system resource properly.

Normally, these tasks would be done by the company's technical architect, and they are solely responsible for the technical specifications used in any product. Based on the features of Tomcat, let us quickly go through the comparison of Tomcat with different versions:

Features

7.x

6.x

5.x

4.x

3.x

Version specifications

Servlet 3.0, JSP 2.2, EL 2.2

Servlet 2.5, JSP 2.1

Servlet 2.4, JSP 2.0

Servlet 2.3, JSP 1.2

Servlet 2.2, JSP 1.1

Stable:

Yes

Yes

Yes

Yes

Yes

Enhancements

Yes

Yes

Unlikely

Highly unlikely

Highly unlikely

Bug Fixes

Yes

Yes

Yes

Highly unlikely

Highly unlikely

Security Fixes

Yes

Yes

Yes

Highly unlikely

Highly unlikely

Releases

Yes

Yes

Yes

Highly unlikely

Highly unlikely

Release Manager

Mark Thomas (markt)

Jean-Frederic Clere (jfclere)

Filip Hanik (fhanik)

Mark Thomas (markt)

Bill Barker (billbarker)

Process

CTR

RTC

RTC

CTR

CTR

Listed on download pages

Yes

Yes

Yes

No

No

JDK version

1.6

1.5

1.4

1.3

1.1

In the previous table, highly unlikely means that the user using the previous version necessarily needs to have the upgraded higher version to support the new improved features. It also involves security fixes for the current version.

Features and enhancements of Apache Tomcat 7

In the previous section, we discussed the various support matrices for Tomcat versions, we are now aware of the support specifications (JDK support, EJB, and Servlet) for Tomcat. Let's try to understand, and quickly review the new features/enhancements for Tomcat 7.

Apache Tomcat 7.x was released with some key improvements over Tomcat 6.x and real time implementation of Servlet 3.0, JSP 2.2, and EL 2.2 specifications. Apart from these, it also solves some major issues from previous releases.

Web application memory leak detection and prevention

Tomcat had a chronological problem of memory leaks in 4.x/5.x versions. While reloading the applications in the entire life cycle of Tomcat, OutOfMemoryError exceptions were generated. Tomcat has put an exceptional effort in tracking down the bugs and issues related to memory, in order to avoid memory leaks.

Servlet 3.0

Tomcat 7 offers great support for Servlet 3.0. Servlet 3.0 helps developers to code very easily and also provides significant support for asynchronous programming techniques. The types of support provided are:

  • Asynchronous Support: Servlet 3.0's asynchronous support has been fully integrated into Tomcat 7. The biggest advantage of asynchronous programming is that the server doesn't have to wait for the response from the resources. For example, if you have 2000 concurrent users using an application, then we cannot allocate 2000 connections to the database and make the connection idle untill we get the response. By using asynchronous programming, your application can handle other user requests while this particular user is waiting for the response from the resources, such as DB, NAS, and so on.

  • Dynamic Configuration: It is again, a very vital feature of Servlet 3.0. Due to Tomcat 7's support for web fragments, developers now don't need to implement the specific library configurations for their application web.xml. This means, you can integrate the library reference in web.xml.

  • Annotation-based Configuration: With the additional support for Servlet 3.0 in Tomcat 7, developers can include decorative programming styles. The biggest advantage of implementing decorator is you can configure rewrite rules in the application servlet classes instead of web servers. Hence, you reduce the dependency on web servers. It also eliminates the need for deployment descriptors.

Improved logging

Tomcat 7 includes two new features for logging, in order to provide a good understanding to the users for log analysis:

  • Asynchronous file handler: The asynchronous handler allows Tomcat to write logs to the disk by a dedicated thread, so that logging operations do not cause any delay in processing threads.

  • Single line log formatter: The single line formatter writes logs in a single line, which is a better feature for administrators.

Aliases

This is the best feature for an administrator. It provides the administrator with the freedom to eliminate the dependency of another web server to host multiple websites. In addition to this, you can host the entire static content (image/JavaScript in a single package).

Note

Important points to remember about Tomcat 7 features

Apache Tomcat 7 can be run through JRE 1.6 or later. It means that we don't have to install the complete Java Development Kit (JDK). This will be really helpful in space crunch issues and the slimming of Java will utilize less memory. But, it is also recommended from the administrator's point of view, to install the complete Java Development Kit as it provides other utilities (jmap, jstack) which are very helpful to administrators. This has an inbuilt eclipse JIT (Just in Time) compiler.

Apache Tomcat 7 resolves class loading conflict issues, such as ClassCastExceptions. ClassCastExceptions mean that there is an issue with class while loading in runtime.