Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Apache Tomcat?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about what Apache Tomcat is, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Apache Tomcat is a long-standing open source Java Servlet container that implements several core Java enterprise specifications, namely Java Servlet,JavaServer Pages (JSP) and WebSockets API.

Tomcat is an Apache Software Foundation project that was first released in 1998, just four years after Java itself. Tomcat began as a reference implementation of the first Java Servlet API and JSP specifications. Although Tomcat is no longer the reference implementation of these two technologies, Tomcat is still the most widely used Java server with a well-tested and validated core engine and good scalability

In this short introduction, you will learn why many software stores choose Tomcat to run Java Web applications. You will get an overview of Tomcat and its usage, as well as the installation instructions for the latest version at the time of this writing.

What kind of server is Tomcat?

The Java ecosystem supports many types of application servers, so let's disambiguate them and see where Tomcat applies:

A Servlet container is an implementation of the Java Servlet specification, which is mainly used for managed Java applets.

A Web server is designed to provide file services from a local system, such as an Apache server.

An Java enterprise application server is a fully mature implementation of the Java EE (present-day Jakarta EE) specification.

In essence, Tomcat is a Servlet and JSP container. The Java servlet encapsulates the code and business logic and defines how requests and responses should be handled at the Java server. JSP is a server-side view rendering technology. As a developer, you write servlet or JSP pages and then let Tomcat handle routing.

Tomcat also includes the Coyote engine, which is a Web server. Thanks to Coyote, Tomcat can be extended to include various Java enterprise specifications and functions, including Java Persistence API (JPA).

Tomcat also has an extended version called TomEE, which includes more enterprise features. I'll give a brief introduction to TomEE later in this article.

Let's start by using Tomcat to host servlet and JSP.

Download and install Tomcat

As an ancient person in the software world, there are many Tomcat versions available. Information about version differences can be found on the Tomcat home page. In general, you can choose the latest stable version.

For our purposes, download the latest version of Tomcat, which is currently Tomcat 9. You can choose to download Tomcat as an archive (.zip or tar.gz) or as an installed service. The best choice is up to you-unless you are certainly not running on Windows, archiving will be used. We will use archiving in this article.

Windows installation of Tomcat

If you are running Windows and want to use the installer, simply download the .exe file and run it. Tomcat installs itself as a service with reasonable default values. It will then inform you of the installation location, and you can proceed as if you unzipped the archive in it.

Step 1. Command line installation

Go to the command line and type gunzip apache-tomcat-9.0.19.tar.gz followed by tar-xf apache-tomcat-9.0.19.tar. This creates the following directory:

/ bin contains scripts to execute Tomcat.

/ webapps is where you will deploy the application.

/ logs is the location of the Tomcat output log. Note that / logs/catalina.out enters the Tomcat log by default. You can use this file to debug problems with application-specific log files.

/ lib is where Tomcat looks for JAR. Here, you will store other packages that are not included with Tomcat, such as JPA.

/ conf is the configuration XML for Tomcat, where you can perform operations such as adding user classes to Tomcat.

Step 2. Start Tomcat

If Tomcat is installed as a service, it is already running. Otherwise, go ahead and start it by typing. / catalina.sh start on the command line. (type. / catalina.sh without arguments to see all available commands). You should now be able to browse to Tomcat's welcome screen in your browser.

Deploy applications in Tomcat

The webapps directory of Tomcat is where you deploy your application. You can put the .war file there, and then Tomcat will run it. The WAR file is the standard wrapper for Web application resources: an JAR file that contains other files that tell the container (in this case, Tomcat) how to run it.

In addition to the standard wrapper, there are three other ways to deploy content in Tomcat.

Explosive deployment

An "explosive" Web application is an application that is not compressed to a WAR file, which means that it still contains all the elements listed in directories and files. The Tomcat archive you unzipped comes with several examples of deployment in this manner, which you can find in the / webapps/examples directory. The advantage of deployment is that you can view the files there without worrying about compression.

If you navigate to http://localhost:8080/examples/, you will find a list of links. The page is rendered by Tomcat through the / webapps/examples/index.html file. Tomcat is providing HTML files from the file system, which is an instance of the Tomcat Coyote engine that acts as a Web server.

Feel free to browse through the examples provided, which give you a good overview of the capabilities of the Tomcat services servlet,JSP and WebSockets.

Tomcat also includes a management application by default, which is located under the / manager path. This application allows you, among other things, to start, stop, and redeploy the application from the Web console.

Provide static content

Files can be provided from the file system or forwarded from Tomcat to another HTTP server, such as Apache. Another common setting is to put a file server (such as Apache or Nginx) in front of the Tomcat and forward your API request to Tomcat. In these cases, the mod_ JK library is used to configure Tomcat and Apache (or even another Web server, such as IIS) to communicate.

To improve performance, mainly in terms of delivering static content, Tomcat also provides native wrappers for Windows and Linux. This is called Tomcat APR, and more information is available here. These are not necessary for a typical use case, but they are easy to understand.

Embedded Tomcat

For a long time, Jetty is the only server that can run as an embedded server. That has changed, and now Tomcat can also run embedded. The idea of using an embedded server is that, so far, you don't have a server that contains application files, but rather an application with a main class (that is, a stand-alone Java application) that invokes server functions from: in its code base. Overall, this provides a simpler and portable development model and quickly becomes the standard. For example, Spring Boot uses an embedded Tomcat instance running in dev mode.

Running an embedded server simplifies the operation because you are now dealing with a single component (application) rather than both application and server deployment. On the other hand, it is still common for Tomcat to run as a stand-alone host.

TomEE

By adding these libraries to Tomcat itself or to application dependencies, you can use more standard Java EE (or Jakarta EE) features with Tomcat. Another option is the TomEE server. TomEE is the same Tomcat engine with additional Java enterprise support, including the popular JPA and CDI (context and dependency injection) API. TomEE's specification is based on the Java EE Web configuration file, so it provides you with not only Tomcat, but also a mature Java EE application server like WildFly or Glassfish.

High availability and clustering

Tomcat supports high availability and clustering. In essence, high availability refers to the ability to fail over to another instance of the server and recreate the session as if nothing had gone wrong. Clustering is the ability to create multiple versions of the same server to handle large amounts of traffic.

Tomcat maintains positive development, keeps pace with changes, and provides a solid and reliable platform for deploying Web applications. Its continued popularity and its choice as the default Java platform for many PaaS systems attest to its continued success.

This is what Apache Tomcat is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report