为什么 Java 应用程序需要应用程序服务器,而 .Net 只需要 IIS Web 服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3954614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 07:31:58  来源:igfitidea点击:

Why does Java apps need an application server and .Net just IIS Web Server?

java.net

提问by Srikar Doddi

Why is there so much confusion in the java world with various servers like apache, tomcat, jboss, jetty, etc and in .Net world it is just IIS that does that job. I would like to understand the need and use of it and am not starting a java vs. .net.

为什么在 Java 世界中使用各种服务器(如 apache、tomcat、jboss、jetty 等)如此混乱,而在 .Net 世界中,只有 IIS 可以完成这项工作。我想了解它的需要和使用,并且不会开始 Java 与 .net。

采纳答案by duffymo

There are several reasons.

有几个原因。

A Java EE app server is a transaction monitor for distributed components. It provides a number of abstractions (e.g., naming, pooling, component lifecycle, persistence, messaging, etc.) to help accomplish this.

Java EE 应用服务器是分布式组件的事务监视器。它提供了许多抽象(例如,命名、池化、组件生命周期、持久性、消息传递等)来帮助实现这一点。

Lots of these services are part of the Windows operating system. Java EE needs the abstraction because it's independent of operating system.

许多这些服务是 Windows 操作系统的一部分。Java EE 需要抽象,因为它独立于操作系统。

It should also be said that the full Java EE specification isn't necessary for developing web applications. JDBC, the part of Java that deals with relational databases, is part of Java SE proper. Java EE adds on servlets, which are HTTP listeners, and Java Server Pages, which is a markup language for generating servlets. You can develop fully functional web applications using just these technologies and Java SE. Tomcat and Jetty are two servlet/JSP engines that can stand in for full Java EE app servers.

还应该说,开发 Web 应用程序不需要完整的 Java EE 规范。JDBC 是 Java 中处理关系数据库的部分,也是 Java SE 的一部分。Java EE 添加了 servlet(HTTP 侦听器)和 Java Server Pages(用于生成 servlet 的标记语言)。您可以仅使用这些技术和 Java SE 开发功能齐全的 Web 应用程序。Tomcat 和 Jetty 是两个 servlet/JSP 引擎,可以代表完整的 Java EE 应用服务器。

If you take note of the fact that .NET has HTTP listeners built into the System.Net module, you realize that it's as if .NET took a page from Java and folded the javax.servlet functionality into the framework.

如果您注意到 .NET 在 System.Net 模块中内置了 HTTP 侦听器这一事实,您就会意识到 .NET 就好像从 Java 中获取了一个页面并将 javax.servlet 功能折叠到框架中。

If you add Spring and a messaging functionality like ActiveMQ or RabbitMQ, you can write complete applications without having to resort to WebLogic, WebSphere, JBoss, or Glassfish. You don't need EJBs or the full Java EE spec.

如果添加 Spring 和 ActiveMQ 或 RabbitMQ 等消息传递功能,您就可以编写完整的应用程序,而无需求助于 WebLogic、WebSphere、JBoss 或 Glassfish。您不需要 EJB 或完整的 Java EE 规范。

UPDATE:

更新:

Spring Boot offers the possibility of developing and running full-featured Java applications as an executable JAR file. There's no need for any Java EE app server, just JDK 8 or higher.

Spring Boot 提供了将全功能 Java 应用程序作为可执行 JAR 文件开发和运行的可能性。不需要任何 Java EE 应用服务器,只需 JDK 8 或更高版本。

回答by Oded

First off, you can run .NET code off Apache using mod_mono, so it is notlimited to IIS. There are also several other web servers (Cassini and XPS come to mind) that will run ASP.NET as well.

首先,您可以使用 mod_mono 在 Apache 上运行 .NET 代码,因此它不仅限于 IIS。还有其他几个 Web 服务器(想到 Cassini 和 XPS)也可以运行 ASP.NET。

In order to run a dynamic web application you need both a web server and an application server. Sometimes these integrate so well they appear to be one and the same, sometimes not.

为了运行动态 Web 应用程序,您需要一个 Web 服务器和一个应用程序服务器。有时这些整合得如此之好,它们似乎是一体的,有时则不是。

In regards to Java - it has always supported more platforms than .NET and has been more open, therefore got integrated to more web servers (on the Linux stack).

关于 Java - 它一直支持比 .NET 更多的平台,并且更加开放,因此被集成到更多的 Web 服务器(在 Linux 堆栈上)。

As both .NET and IIS are technologies that came from Microsoft, ASP.NET and the application server aspects of it (aspnet_isapi.dll) were bundled with IIS and the different .NET installers integrate with IIS. Of course, Microsoft only implemented it on their OS and for their web server.

由于 .NET 和 IIS 都是来自 Microsoft 的技术,因此 ASP.NET 及其应用服务器方面 (aspnet_isapi.dll) 与 IIS 捆绑在一起,不同的 .NET 安装程序与 IIS 集成。当然,微软只在他们的操作系统和他们的网络服务器上实现了它。

回答by Dr. Snoopy

Because Java EE is a specification, not a product itself. Remember that Java is a lot more open than .NET (In the specification sense).

因为 Java EE 是一种规范,而不是产品本身。请记住,Java 比 .NET 开放得多(在规范意义上)。

Each application server has different features, different performance, different target users/enterprises, different price tags, runs in different platforms, require different hardware. Differentiation is why those all application servers exists, one size does not fit all.

每个应用服务器都有不同的特性、不同的性能、不同的目标用户/企业、不同的价格标签、运行在不同的平台上、需要不同的硬件。差异化是所有应用服务器都存在的原因,一种尺寸并不适合所有应用程序服务器。

回答by Yishai

Apache is very analogous to IIS, and doesn't have much to do with Java.

Apache 与 IIS 非常相似,与 Java 没有太大关系。

Application Servers in Java provide additional services that .NET provides in various ways, with different products or from the Windows operating system.

Java 中的应用程序服务器提供了 .NET 以各种方式提供的附加服务,包括不同的产品或来自 Windows 操作系统。

Apache is typically used in Java deployments as a proxy to an application server behind it, and potentially serves static content, or handles SSL, and similar concerns. It is entirely optional, although there are good reasons to use it.

Apache 通常在 Java 部署中用作其背后应用程序服务器的代理,并可能提供静态内容或处理 SSL 和类似问题。尽管有充分的理由使用它,但它完全是可选的。

Tomcat and Jetty are basically java web servers, which provide a defined framework (Servlets among other things) for creating dynamic web sites with Java code. They are often components of a larger application server, or can be deployed alone.

Tomcat 和 Jetty 基本上是 Java Web 服务器,它们提供了一个定义的框架(Servlet 等),用于使用 Java 代码创建动态网站。它们通常是大型应用服务器的组件,或者可以单独部署。

JBoss is an example of an application server (Glassfish and Weblogic are two very common others), which provides the full J2EE specification. The idea behind the J2EE specification is to allow a defined way to build an application server so that an application can be switched between different application servers from different vendors that comply with the spec. The specification is about how to interact with defined services that are useful for server-side program.

JBoss 是应用服务器的一个例子(Glassfish 和 Weblogic 是另外两个非常常见的),它提供了完整的 J2EE 规范。J2EE 规范背后的想法是允许以定义的方式构建应用服务器,以便应用程序可以在来自不同供应商的符合规范的不同应用服务器之间切换。该规范是关于如何与对服务器端程序有用的已定义服务进行交互。

回答by SemanticTom

The choices off tools are one of the advantages and disadvantages of Java, look at the available Java Web Developement Frameworks,you could evaluate them endlessly just to decide. in .Net it's pretty much MVC. With servers it's relatively simple. Most go to Tomcat if they need a web server and JBoss if they need a free application server though. The reasons for this have already been said, J2EE is a specification.

工具的选择是 Java 的优点和缺点之一,看看可用的 Java Web 开发框架,你可以无休止地评估它们来决定。在 .Net 中,它几乎是 MVC。使用服务器相对简单。大多数人在需要 Web 服务器时使用 Tomcat,如果需要免费的应用程序服务器,则使用 JBoss。原因已经说了,J2EE是一个规范。

回答by Patrick Krecker

One reason is that writing a servlet is as easy as implementing the javax.servlet.Servlet interface in a concrete class. Servlet containers, then, only need to support a fairly simple API in order to call themselves web servers. This makes setting out to develop a servlet container extremely simple because of this limited contract of functionality.

原因之一是编写 servlet 就像在具体类中实现 javax.servlet.Servlet 接口一样简单。那么,Servlet 容器只需要支持一个相当简单的 API 就可以调用自己的 Web 服务器。由于这种有限的功能契约,这使得开始开发 servlet 容器变得非常简单。

回答by Thorbj?rn Ravn Andersen

This is because Sun and Microsoft had very different goals with their software, and ways to reach that goal.

这是因为 Sun 和 Microsoft 的软件目标和实现该目标的方法截然不同。

The Sun mantra for Java has been right from the beginning "Write once, run everywhere", and that has resulted in that much effort has been put into creating _API_s that specify how the environment should look like to allow a minimalistic piece of code do its job.

Sun 对 Java 的口号从一开始就是正确的“一次编写,到处运行”,这导致我们投入了大量精力来创建 _API_s,以指定环境应该是什么样子,以允许一段极简的代码完成它的工作工作。

The API for "process a web request and return a web response" was named Servlets, and has been extremely successful due to it filling a void and being well specified. Allmainstream Java based web servers I know of allow to run servlets. An early implementation of a complete servlet capable web server is only 1500 linesLater this was expanded to include JSP's to provide for HTML with server side code (like PHP).

用于“处理 Web 请求并返回 Web 响应”的 API 被命名为 Servlets,由于它填补了空白并得到了很好的指定,因此非常成功。 我所知道的所有主流基于 Java 的 Web 服务器都允许运行 servlet。一个完整的支持 servlet 的 Web 服务器的早期实现只有 1500 行。后来扩展到包括 JSP,以提供带有服务器端代码的 HTML(如 PHP)。

For any solution to be truly scalable, including web solutions, it means that eventually the load is so high that one computer is not powerful enough to run it on its own anymore. A scalable solution MUSTbe able to spread over multiple computers aware of each other, and that single requirement brings a LOT of other things to the table:

对于任何真正具有可扩展性的解决方案,包括 Web 解决方案,这意味着最终负载如此之高,以至于一台计算机的功能不足以再单独运行它。一个可扩展的解决方案必须能够分布在多台相互了解的计算机上,并且这个单一的要求带来了很多其他的东西:

  • Code must be able to invoke code running on a different computer (EJB's).
  • Data must be available to all computers in a consistent way (database).
  • Access to said database must be efficient (database connection pooling). ... and much much more
  • 代码必须能够调用在不同计算机(EJB)上运行的代码。
  • 数据必须以一致的方式(数据库)提供给所有计算机。
  • 对所述数据库的访问必须是高效的(数据库连接池)。......还有更多

Sun then created API's for all of the functions they found were necessary for this to run, and named it "Java Enterprise Edition" (those days the word "Enterprise" was used for a lot of things), and created a system implementing all these API's which people could buy and use.

然后,Sun 为他们认为运行所需的所有功能创建了 API,并将其命名为“Java 企业版”(当时“企业”一词用于很多事情),并创建了一个实现所有这些功能的系统人们可以购买和使用的 API。

The difference between Microsoft and Sun now comes in play. Here Microsoft would just make IIS public, and say "use these API's" in clients but not actually want anybody to create another server providing these APIs. Because they want to sell Windows to run it!

Microsoft 和 Sun 之间的差异现在开始发挥作用。在这里,Microsoft 只会公开 IIS,并在客户端中说“使用这些 API”,但实际上并不希望任何人创建另一个提供这些 API 的服务器。因为他们要卖Windows来运行它!

Sun wanted people to use the language instead, so they made it possible for ANYONE to implement the Java EE specification, but they had to pass a rigorious test suite from Sun (and pay) to be allowed to usethe Java EE brand. This has caused a large number of Java EE servers to be available where you usually can reuse the core business logic, but have to configure the Java EE server to provide the resources the application needs.

Sun 希望人们改用该语言,因此他们让任何人都可以实现 Java EE 规范,但他们必须通过 Sun(并付费)的严格测试套件才能被允许使用Java EE 品牌。这导致大量 Java EE 服务器可用,您通常可以重用核心业务逻辑,但必须配置 Java EE 服务器以提供应用程序所需的资源。

See http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#Certified_application_serversfor the state of servers today. Both commercial and open source are available based on your needs - pick the one that suits you best.

有关当今服务器的状态,请参阅http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#Certified_application_servers。商业和开源都可以根据您的需要使用 - 选择最适合您的。

So, the reason is that Java EE is a set of well defined API's that anyone can implement, and they have.

因此,原因是 Java EE 是一组定义明确的 API,任何人都可以实现,而且他们拥有。