568

What is the difference in terms of functionality between the Apache HTTP Server and Apache Tomcat?

I know that Tomcat is written in Java and the HTTP Server is in C, but other than that I do not really know how they are distinguished. Do they have different functionality?


  • I have added a summary in my blog, maybe it helps someone: tugay.biz/2014/11/what-is-tomcat-is-it-web-server-what.html - Koray Tugay
  • I was wondering exactly what the OP was asking, and I don't see why it was closed. Luckily there are answers. - Florian F
  • Apache web server and Apache Tomcat are two different tools tuned for different purposes. If we can no longer distinguish their use cases by facts and expertise then we are come to a sorry state. This drive to close "argumentative" questions has over-reached. Perhaps moderators need to be more informed and less opinionated. As @FlorianF says, at least there are answers now. - Anil G

8 답변


414

Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.

So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.

Tomcat is a servlet container. A servlet, at the end, is a Java class. JSP files (which are similar to PHP, and older ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine.


  • What do you intend by "Apache is [...] serving HTTP"? Isn't Tomcat also serving (hypertext aka) HTTP? Why can't Tomcat simply be a "mod_java" Apache module? Can you explain? - Peterino
  • Tomcat is a servlet container. A servlet, at the end, is a Java class. JSP files (which are similar to PHP oder ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine. - Apart from that, this forum here explains the difference between Apache HTTPD and Tomcat pretty well: coderanch.com/t/85182/Tomcat/… - Peterino
  • Tomcat does indeed bring with it a capable web server. Tomcat is a Servlet/JSP container and also offers a web server. Tomcat's web server is quite good, able to handle most small and medium web site needs. With support for Java NIO and 64-bit memory, even some larger scale web sites may be served well by Tomcat's Catalina module. For various reasons, some folks choose to ignore Catalina and instead use Tomcat's Servlet capabilities behind the Apache httpd web server product. - Basil Bourque
  • Correction to my comment: Coyote is the module in Tomcat responsible for web serving. Catalina is the module that does Servlets. Jasper is the module that handles JSPs. - Basil Bourque
  • @KorayTugay Yes. Tomcat = ( Web Server + Servlet container + JSP environment ). The web server is ON by default when you run Tomcat’s startup.sh script, listening on port 8080 for incoming connections (HTTP calls). Tomcat is pure Java, with its own web server implementation (Coyote). The Apache HTTP Server (AHS), in contrast, has a completely separate implementation of a web server, using native C/C++ code. AHS is very flexible and powerful, but is often overkill. Tomcat's own web server works very well. Use AHS only if truly needed. - Basil Bourque

99

In addition to the fine answers above, I think it should be said that Tomcat has it's own HTTP server built into it, and is fully functional at serving static content too. Depending on your java virtual machine configuration it can actually outperform going through traditional connectors in apache such as mod_proxy and mod_jk.

That said a fully optimized Tomcat server should serve static files fast and if you have Java servlets, JSPs and ColdFusion files in addition to static content you may find tomcat does an excellent job by itself.


  • True. And many people still use an extra Apache setup besides their Tomcat.. which is unnecessary in most cases. - Marco Schoolenberg
  • The most powerful part of apache http that few other servers support is ability to reroute and rewrite the request before application has to see it, namely through mod_rewrite engine and conditional environment injection. mod_proxy provides rudimentary load balancing (and combined with mod_jk provides rudimentary sticky session/shared state between load balanced tomcat instances). - cowbert

67

  1. Apache is a general-purpose http server, which supports a number of advanced options that Tomcat doesn't.
  2. Although Tomcat can be used as a general purpose http server, you can also set up Apache and Tomcat to work together with Apache serving static content and forwarding the requests for dynamic content to Tomcat.


  • Isn't all web is static at the end? My understanding is, Tomcat generates "a" static content (dynamically) then Apache will serve this. So Tomcat will never actually serve dynamic content or anything, it will only generate it when required. - Koray Tugay
  • @KorayTugay You are confusing your terms. "Generate it when required" is exactly what "dynamic" means, and is the very opposite of "static". The main purpose of the Apache HTTP Server is to serve static content, while the main purpose of Servlet technology is to generate content on-the-fly (dynamic content). - Basil Bourque
  • @BasilBourque I was confused with Tomcat actually serving content here. It will only generate the content, it will not serve it when used together with Apache Http Server. Probably you are right and I am just confused but to me I would still say, when used together, Apache serves, Tomcat generates static content when required. If not Apache is used, Coyote in Tomcat will do the serving, while Catalina and Jesper are generating the dynamic content. - Koray Tugay
  • @KorayTugay Yes, your last comment is correct. If using Apache HTTP Server + Tomcat, then web browsers only "see" AWS with no clue that Tomcat is working behind the curtains. AWS is a middle-man between the web browser clients and Tomcat. If using Tomcat alone, then the Coyote module in Tomcat takes the place of AWS to field requests from web browser clients. I recommend the latter (Tomcat alone) unless you know you have very special needs that would be better addressed by AWS. - Basil Bourque

24

Tomcat is primarily an application server, which serves requests to custom-built Java servlets or JSP files on your server. It is usually used in conjunction with the Apache HTTP server (at least in my experience). Use it to manually process incoming requests.

The HTTP server, by itself, is best for serving up static content... html files, images, etc.


  • I doubt Tomcat is primarily an application server statement. - Rachel
  • tomcat is primarily meant to be an application server. though it does server static content as well. - Scalable
  • Yes Tomcat is indeed primarily an application server, if the term is meant in the sense of a Servlet container generating dynamic content delivered to web browsers. As one of the first Servlet containers, that is Tomcat's reason for being. - Basil Bourque
  • tomcat is not an application server, it is a web server. javajee.com/web-server-web-container-and-application-server - Prateek Mishra
  • @PrateekMishra Based on the link you provided, your statement that tomcat is a web server is incorrect; it is (primarily) a web container, also known as a servlet container. - skomisa

17

an apache server is an http server which can serve any simple http requests, where tomcat server is actually a servlet container which can serve java servlet requests.

Web server [apache] process web client (web browsers) requests and forwards it to servlet container [tomcat] and container process the requests and sends response which gets forwarded by web server to the web client [browser].

Also you can check this link for more clarification:-

https://sites.google.com/site/sureshdevang/servlet-architecture

Also check this answer for further researching :-

https://softwareengineering.stackexchange.com/a/221092


12

If you are using java technology(Servlet/JSP) for making web application you will probably use Apache Tomcat. However, if you are using other technologies like Perl, PHP or ruby, its better(easier) to use Apache HTTP Server.


  • This answer makes no sense to me. The first sentence is wrong in that there are many other Servlet/JSP containers besides Tomcat, some quite popular such as Jetty, JBoss/Wildfly, Glassfish, WebSphere, and many more. While popular, Tomcat does not dominate, with only a minority of market share. As for the second sentence, Tomcat is often used as a Servlet container behind Apache HTTP Server. And PHP etc. are often used with several other web Servers such as Nginx, Lighttpd, and others. - Basil Bourque

3

Well, Apache is HTTP webserver, where as Tomcat is also webserver for Servlets and JSP. Moreover Apache is preferred over Apache Tomcat in real time


  • This question is quite old, and your answer seems to duplicate ones that have been posted long ago. Answers are appreciated but new answers should help add to the conversation. - GargantuChet

-1

Apache is an HTTP web server it serve as HTTP but apache tomcat is an java servlet container,IT FEATURES Same as web server customized to execute java servlet and JSP pages.


  • This answer is a bit confusing - mac
  • yes answer is bit confusing as @ Basil Bourque said above " Coyote is the module in Tomcat responsible for web serving, Catalina is the module that does Servlets. and Jasper is the module that handles JSPs " now it gives clarity on how "TOMCAT FEATURES Same as web server customized to execute java servlet and JSP pages!!!! " - Dev

Linked


Related

Latest