Tomcat Java Ee

The Apache Tomcat Project is proud to announce the release of 0.2.0 of the Apache Tomcat Migration Tool for Jakarta EE. This release contains a number of bug fixes and improvements compared to version 0.1.0. Choose the right server for your Java EE application and learn the pros and cons of some of the most popular options. In this course, instructor Michael Rogers compares and contrasts the top four: Apache Tomcat, Oracle WebLogic, WildFly, and Payara, an app server derived from Glassfish. Java EE applications are created from components. Components are self-contained software units that provide certain functions and having the ability to communicate with other components. They shall include in the appropriate classes and any other necessary files. They form a kind of building blocks that make up the application.

Written by Nam Ha Minh
Last Updated on 21 December 2019 Print Email
RESTful Web Services is a programming model based on REST (Representational State Transfer) architecture, which makes use of standard HTTP methods (GET, POST, PUT, DELETE…) to manipulate resources identified by URIs, and JSON/XML to exchange data between servers and clients. RESTful web services is commonly used to develop APIs for web-based applications because of its simplicity, lightweight, performance, reliability and scalability.In this tutorial, I will help you get started with RESTful web services in Java by developing a Java web application running on Apache Tomcat server – this web application hosts Restful web services powered by Jersey – an open source framework for developing RESTful web services in Java. Jersey is a reference implementation of JAX-RS (Java API for RESTful Web Services).You will also learn to test RESTful web services using cURL and Postman tools, and code a RESTful web services client program using Jersey client API.To follow this tutorial, you should be familiar with web development in Java with Eclipse IDE, Apache Tomcat server and Maven.

1. Create Project and Specify Jersey Dependency

In Eclipse IDE, create a Dynamic Java Web project named as HelloREST. And convert it to Maven project by right clicking on the project, click Configure > Convert to Maven project. Open the pom.xml Tomcat Java Eefile and declare the following dependency:This dependency is required to develop RESTful web services in Java, using Jersey framework – an implementation of Java API for RESTful Web Services (JAX-RS).Use the version 2.25.x if your Tomcat running on JDK 8. In case you use JDK 11 or later, you should use newer version, e.g. Jersey 2.29.1 like this:For Jersey 2.26.x or newer, you must also declare the Jersey Inject dependency as shown above. So let use the Jersey version 2.29.1 because it works well both on JDK 8 and recent JDK versions (JDK 11 or newer).

2. Code a Hello World RESTful Web Service

Create a new class Hello under the package net.codejava with the following code:Look, this is your first class for RESTful web services. Let me explain:The @Path annotation defines the relative URL that forms the URI that identifies a resource. You can use this annotation on both class level or method level.The @GET annotation specifies that the annotated method, direBonjour() handles HTTP GET request. Jersey provides annotations corresponding to HTTP methods: @POST, @PUT, @DELETE…The @Produces annotation specifies the content type of the response, which is text plain in our code. You can also specify text/xml, text/html, JSON, etc.And you can see the method direBonjour() returns a plain text, saying hello world in French – as response to the clients.

3. Configure Jersey Servlet Container

Next, we need configure Jersey servlet in the web deployment descriptor (web.xml) file like this:Note that we need to specify the package name that contains the classes that need to be exposed as RESTful web services, as an initialization parameter of Jersey servlet; and the URL pattern will be handled by Jersey servlet container.Now, you can add this project to Tomcat and start the server to test the web service.

4. Test RESTful Web Service using web browser

Open a web browser (e.g. Chrome) and type the following URL:


Then you should see the following page:You see, the browser displays the plain text response sent by the web service. Now, add second method to the HelloResourceclass:This method returns a HTML response. Refresh the browser and you should see:You see, the browser now shows the HTML response sent from the web service (a web browser always expects Text/HTML response). That means with the same URI, the response representation can be different, depending on content type accepted by the clients.

5. Using JSON for RESTful web services

JSON is a preferred format for data representation in RESTful web services because of its simplicity and lightweight.To use JSON with Jersey, you need to add the following dependency to the pom.xml file:Now, update the HelloResourceclass to have a new method that produces JSON response, as follows:This method returns a simple piece JSON data. If you refresh the browser, you will see nothing changes because the browser doesn’t expect JSON response by default.

6. Test RESTful Web Service using curl

curl is a command-line tool which is widely used to test RESTful web services APIs. If you’re using Windows 10, curl is shipped with the operating system by default. If not, you can download curl here.Type the following command to test our web service:

curl http://localhost:8080/HelloREST/rest/bonjour

Then you can see JSON response:You can use the –v option (versbose) to see more details such as request headers and response headers. For example:

curl -v http://localhost:8080/HelloREST/rest/bonjour

Then you can see the output something like this:You can use the –H option to specify a HTTP header in the request. For example:

curl -H 'Accept: text/html' http://localhost:8080/HelloREST/rest/bonjour

This command tells the server that the client expects response format to be of text/html. Hence the following response:And the following curl command will get plain text response from the server:

curl -H 'Accept: text/plain' http://localhost:8080/HelloREST/rest/bonjour

7. Test RESTful Web Service using Postman

Postman is a GUI tool that can be used to test web service APIs. Click here download and install Postman on your computer (you have to create an account to use – free). Then create a new collection and a request under this collection. Then type a URL and click Send, as shown below:As you can see, Postman is easier to use and more advanced than curl.

8. Code a RESTful Web Service Client program

You can use Jersey Client API to write client programs that consume RESTful web services. Create a new Maven project, e.g. HelloClientand add the following dependencies to the pom.xml file:Then code a simple RESTful web service client program as follows:This program simply sends a GET request to the server at the specified URI and reads the response. Run this program and you should see the following output:

{'name':'greeting', 'message':'Bonjour tout le monde!'}

This is JSON response because the client expects application/json as the accepted media type.Congratulations, you have done your first hello world RESTful web services application, with both server and client. For your reference, you can download the sample project in the attachments section below.You can also watch the video version of this tutorial below:

Other Java Web Services Tutorial:

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.
[RESTful client server project]20 kB


Apache Tomcat Versions

Apache Tomcat® is an open source software implementation of asubset of the Jakarta EE (formally Java EE) technologies. Different versions ofApache Tomcat are available for different versions of the specifications. Themapping betweenthespecifications and the respective Apache Tomcat versions is:

Servlet SpecJSP SpecEL SpecWebSocket SpecAuthentication (JASIC) SpecApache Tomcat VersionLatest Released VersionSupported Java Versions and later and later and later (superseded)8.0.53 (superseded)7 and later and later
(7 and later for WebSocket) (archived)6.0.53 (archived)5 and later
2.42.0N/AN/AN/A5.5.x (archived)5.5.36 (archived)1.4 and later
2.31.2N/AN/AN/A4.1.x (archived)4.1.40 (archived)1.3 and later
2.21.1N/AN/AN/A3.3.x (archived)3.3.2 (archived)1.1 and later

Each version of Tomcat is supported for any stable Java release that meetsthe requirements of the final column in the table above.

Tomcat should also work on any Java early access build that meets therequirements of the final column in the table above. For example, users weresuccessfully running Tomcat 8 on Java 8 many months before the first stable Java8 release. However, users of early access builds should be aware of thefollowing:

  • It is not unusual for the initial early access builds to contain bugs that can cause problems for web applications running on Tomcat.
  • If the new Java version introduces new language features then the default JSP compiler may not support them immediately. Switching the JSP compiler to javac may enable these new language features to be used in JSPs.
  • If you do discover an problem using a Java early access build, please ask for help. The Tomcat user's mailing list is probably the best place to start.

The releases are described in more detail below to help you determinewhich one is right for you. More details about each release can be found inthe associated release notes.

Please note that although we offer downloads and documentation of olderreleases, such as Apache Tomcat 7.x, we strongly encourage users to use thelatest stable version of Apache Tomcat whenever possible. We recognize thatupgrading across major versions may not be a trivial task, and some support isstill offered on the mailing list for users of old versions. However, becauseof the community-driven support approach, the older your version, fewer peoplewill be interested or able to support you.

Tomcat java ee

Alpha / Beta / Stable

When voting for a release, reviewers specify the stability level that theyconsider the release has reached. Initial releases of a new major versiontypically process from Alpha, through Beta to Stable over a period of severalmonths. However, the Stable level is only available once the Java specificationsthe release implements have been finalised. This means a release that in allother respects is considered stable, may still be labelled as Beta if thespecifications are not final.

The download pages will always show the latest stable release and any newerAlpha or Beta release if one exists. Alpha and beta releases are always clearlymarked on the download pages.

Stability is a subjective judgement and you should always read carefully therelease notes for any version you intend to make use of. If you are an earlyadopter of a release, we would love to hear your opinion about its stability aspart of the vote: it takes place on the development mailinglist.

Alpha releases may contain large amounts of untested/missingfunctionality required by the specification and/or significant bugs and are notexpected to run stably for any length of time.

Beta releases may contain some untested functionality and/ora number of relatively minor bugs. Beta releases are not expected to run stably.

Stable releases may contain a small number of relativelyminor bugs. Stable releases are intended for production use and are expected torun stably for extended periods of time.

Apache Tomcat 10.x

Apache Tomcat 10.x is the current focus of development. Itbuilds on Tomcat 9.0.x and implements the Servlet5.0, JSP 3.0, EL 4.0, WebSocket 2.0 and Authentication 2.0 specifications (the versions required byJakarta EE 9 platform).

Apache Tomcat 9.x

Apache Tomcat 9.x is the current focus of development. Itbuilds on Tomcat 8.0.x and 8.5.x and implements the Servlet4.0, JSP 2.3, EL 3.0, WebSocket 1.1 and JASPIC 1.1 specifications (the versions required byJava EE 8 platform). In addition to this, it includesthe following significant improvements:

  • Adds support for HTTP/2 (requires either running on Java 9 (since Apache Tomcat 9.0.0.M18) or the Tomcat Native library being installed)
  • Adds support for using OpenSSL for TLS support with the JSSE connectors (NIO and NIO2)
  • Adds support for TLS virtual hosting (SNI)

Apache Tomcat 8.x

Apache Tomcat 8.0.x builds on Tomcat 7.0.x and implements theServlet 3.1, JSP 2.3, EL 3.0and WebSocket 1.1 specifications. In additionto that, it includes the following significant improvements:

  • A single, common resources implementation to replace the multiple resource extension features provided in earlier versions.

Apache Tomcat 8.5.x supports the same Servlet, JSP, EL, andWebSocket Specification versions as Apache Tomcat 8.0.x. In addition to that,it also implements the JASPIC 1.1 specification.

It was created in March 2016 as a fork from Tomcat 9.0.0.M4 (alpha)milestone release. It provides HTTP/2 support and other features fromTomcat 9.x codebase, while being compatible with Tomcat 8.0 runtime andspecification requirements. (A stable release of Tomcat 9.0 could not becreated at that time, as Java EE specifications targeted by Tomcat 9 werefinalized only a few years later).

Tomcat 8.5 is thought as a replacement for Tomcat 8.0. Please refer toMigration guide for guidance on migrating toTomcat 8.5.

Apache Tomcat 8.5.x includes the following significant improvements:

  • Adds support for HTTP/2 (requires the Tomcat Native library)
  • Adds support for using OpenSSL for TLS support with the JSSE connectors (NIO and NIO2)
  • Adds support for TLS virtual hosting (SNI)

The following technologies were removed in Apache Tomcat 8.5.x:

  • BIO implementation of HTTP and AJP connectors
  • Support for Comet API

There are significant changes in many areas under the hood, resulting inimproved performance, stability, and total cost of ownership. Please referto the Apache Tomcat 8.5 Changelog for details.

Users of Tomcat 8.0 should be aware that Tomcat 8.0 has now reachedend of life. Users of Tomcat 8.0.x shouldupgrade to Tomcat 8.5.x or later.

Apache Tomcat 7.x

Apache Tomcat 7.x builds upon the improvements made inTomcat 6.0.x and implements the Servlet 3.0,JSP 2.2, EL 2.2 andWebSocket 1.1 specifications. In additionto that, it includes the following improvements:

  • Web application memory leak detection and prevention
  • Improved security for the Manager and Host Manager applications
  • Generic CSRF protection
  • Support for including external content directly in a web application
  • Refactoring (connectors, lifecycle) and lots of internal code clean-up

Users of Tomcat 7 should be aware thatend of life has been announced for Tomcat 7.Users of Tomcat 7.x should upgrade to Tomcat 8.5.x or later.

Apache Tomcat 6.x

Apache Tomcat 6.x builds upon the improvements made inTomcat 5.5.x and implements the Servlet 2.5 andJSP 2.1 specifications. In addition to that, it includes thefollowing improvements:

  • Memory usage optimizations
  • Advanced IO capabilities
  • Refactored clustering

Users of Tomcat 6 should be aware that Tomcat 6 has now reachedend of life. Users of Tomcat 6.x shouldupgrade to Tomcat 7.x or later.

Apache Tomcat 5.x

Apache Tomcat 5.x is available for download from thearchives.

Apache Tomcat 5.5.x supports the same Servlet and JSPSpecification versions as Apache Tomcat 5.0.x. There are significant changesin many areas under the hood, resulting in improved performance, stability,and total cost of ownership. Please refer to the Apache Tomcat 5.5 Changelogfor details.

Apache Tomcat 5.0.x improves on Apache Tomcat 4.1 in manyways, including:

  • Performance optimizations and reduced garbage collection
  • Refactored application deployer, with an optional standalone deployerallowing validation and compilation of a web application before puttingit in production
  • Complete server monitoring using JMX and the manager web application
  • Scalability and reliability enhancements
  • Improved Taglibs handling, including advanced pooling and tag plugins
  • Improved platform integration, with native Windows and Unix wrappers
  • Embedding using JMX
  • Enhanced Security Manager support
  • Integrated session clustering
  • Expanded documentation

Users of Tomcat 5 should be aware that Tomcat 5 has now reachedend of life. Users of Tomcat 5.x shouldupgrade to Tomcat 7.x or later.

Tomcat Java Ee Example

Apache Tomcat 4.x

Apache Tomcat 4.x is available for download from thearchives.

Apache Tomcat 4.x implements a new servlet container (calledCatalina) that is based on completely new architecture. The 4.x releasesimplement the Servlet 2.3 and JSP 1.2specifications.

Apache Tomcat 4.1.x is a refactoringof Apache Tomcat 4.0.x, and contains significant enhancements, including:

  • JMX based administration features
  • JSP and Struts based administration web application
  • New Coyote connector (HTTP/1.1, AJP 1.3 and JNI support)
  • Rewritten Jasper JSP page compiler
  • Performance and memory efficiency improvements
  • Enhanced manager application support for integration with developmenttools
  • Custom Ant tasks to interact with the manager application directlyfrom build.xml scripts

Apache Tomcat 4.0.x. Apache Tomcat 4.0.6 is the old productionquality release. The 4.0 servletcontainer (Catalina) has been developed from the ground up for flexibility andperformance. Version 4.0 implements the final released versions of the Servlet2.3 and JSP 1.2 specifications. As required by the specifications, Apache Tomcat 4.0also supports web applications built for the Servlet 2.2 and JSP 1.1specifications with no changes.

Users of Tomcat 4 should be aware that Tomcat 4 has now reachedend of life. Users of Tomcat 4.x should upgrade to Tomcat 7.x orlater.

Apache Tomcat 3.x

Apache Tomcat 3.x is available for download from thearchives.

  • Version 3.3 is the current production quality release forthe Servlet 2.2 and JSP 1.1 specifications. Apache Tomcat 3.3 is the latestcontinuation of the Apache Tomcat 3.x architecture; it is more advanced then 3.2.4,which is the 'old' production quality release.
  • Version 3.2.4 is the 'old' production quality release and is now inmaintenance only mode.
  • Version 3.1.1 is a legacy release.

All Apache Tomcat 3.x releases trace their heritage back to theoriginal Servlet and JSP implementations that Sun donated to the ApacheSoftware Foundation. The 3.x versions all implement the Servlet2.2 and JSP 1.1 specifications.

Apache Tomcat 3.3.x. Version 3.3.2 is the current productionquality release. It continues the refactoring that was begun in version 3.2 andcarries it to its logical conclusion. Version 3.3 provides a much more modulardesign and allows the servlet container to be customized by adding and removingmodules that control the processing of servlet requests. This version alsocontains many performance improvements.

Apache Tomcat 3.2.x. Version 3.2 added few new featuressince 3.1; the major effort was a refactoring of the internals to improveperformance and stability. The 3.2.1 release, like 3.1.1, was a securitypatch. Version 3.2.2 fixed a large number of bugs and all knownspecification compliance issues. Version 3.2.3 was a security update thatcloses a serious security hole. Version 3.2.4 is a minor bug fix release.All users of Apache Tomcat versions prior to 3.2.3 should upgrade as soon aspossible. With the exception of fixes for critical security related bugs,development on the Apache Tomcat 3.2.x branch has stopped.

Apache Tomcat 3.1.x. The 3.1 release contained severalimprovements over Apache Tomcat 3.0, including servlet reloading, WAR filesupport and added connectors for the IIS and Netscape web servers. Thelatest maintenance release, 3.1.1, contained fixes for security problems.There is no active development ongoing for Apache Tomcat 3.1.x. Users of Apache Tomcat3.1 should update to 3.1.1 to close the security holes and they arestrongly encouraged to migrate to the current production release, Apache Tomcat3.3.

Apache Tomcat 3.0.x. Initial Apache Tomcat release.

Tomcat Java Ee Setup

Users of Tomcat 3 should be aware that Tomcat 3 has now reachedend of life. Users of Tomcat 3.x should upgrade to Tomcat 7.x orlater.