简体   繁体   English

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

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

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. 为什么java世界中存在如此多的混乱,包括apache,tomcat,jboss,jetty等各种服务器,而在.Net世界中,只有IIS才能完成这项工作。 I would like to understand the need and use of it and am not starting a java vs. .net. 我想了解它的需要和使用,并没有启动java vs. .net。

There are several reasons. 有几个原因。

A Java EE app server is a transaction monitor for distributed components. Java EE应用服务器是分布式组件的事务监视器。 It provides a number of abstractions (eg, naming, pooling, component lifecycle, persistence, messaging, etc.) to help accomplish this. 它提供了许多抽象(例如,命名,池,组件生命周期,持久性,消息传递等)来帮助实现这一目标。

Lots of these services are part of the Windows operating system. 许多这些服务都是Windows操作系统的一部分。 Java EE needs the abstraction because it's independent of operating system. Java EE需要抽象,因为它独立于操作系统。

It should also be said that the full Java EE specification isn't necessary for developing web applications. 还应该说,开发Web应用程序不需要完整的Java EE规范。 JDBC, the part of Java that deals with relational databases, is part of Java SE proper. JDBC是处理关系数据库的Java的一部分,是Java SE的一部分。 Java EE adds on servlets, which are HTTP listeners, and Java Server Pages, which is a markup language for generating servlets. Java EE添加了作为HTTP侦听器的servlet和Java Server Pages,后者是用于生成servlet的标记语言。 You can develop fully functional web applications using just these technologies and Java SE. 您可以使用这些技术和Java SE开发功能齐全的Web应用程序。 Tomcat and Jetty are two servlet/JSP engines that can stand in for full Java EE app servers. 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. 如果您添加Spring和ActiveMQ或RabbitMQ等消息传递功能,您可以编写完整的应用程序,而无需使用WebLogic,WebSphere,JBoss或Glassfish。 You don't need EJBs or the full Java EE spec. 您不需要EJB或完整的Java EE规范。

UPDATE: 更新:

Spring Boot offers the possibility of developing and running full-featured Java applications as an executable JAR file. Spring Boot提供了将全功能Java应用程序开发和运行为可执行JAR文件的可能性。 There's no need for any Java EE app server, just JDK 8 or higher. 不需要任何Java EE应用服务器,只需JDK 8或更高版本。

This is because Sun and Microsoft had very different goals with their software, and ways to reach that goal. 这是因为Sun和微软的软件目标非常不同,以及实现这一目标的方法。

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. Java的Sun咒语从一开始就是“一次编写,随处运行”,这导致创建_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. 用于“处理Web请求并返回Web响应”的API被命名为Servlets,并且由于填充了空白并且被明确指定,因此非常成功。 All mainstream Java based web servers I know of allow to run servlets. 我所知道的所有基于Java的主流Web服务器都允许运行servlet。 An early implementation of a complete servlet capable web server is only 1500 lines Later this was expanded to include JSP's to provide for HTML with server side code (like PHP). 一个完整的支持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. 对于任何真正可扩展的解决方案,包括Web解决方案,这意味着最终负载非常高,以至于一台计算机的功能不足以自行运行它。 A scalable solution MUST be able to spread over multiple computers aware of each other, and that single requirement brings a LOT of other things to the table: 一个可扩展的解决方案必须能够分散在多台计算机之间,这个单一的需求带来了很多其他的东西:

  • Code must be able to invoke code running on a different computer (EJB's). 代码必须能够调用在不同计算机(EJB)上运行的代码。
  • 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 ......还有更多

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 Enterprise Edition”(当时“Enterprise”这个词用于很多事情),并创建了一个实现所有这些功能的系统人们可以购买和使用的API。

The difference between Microsoft and Sun now comes in play. 微软和Sun之间的区别现在正在发挥作用。 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. 在这里,微软只会公开IIS,并在客户端中说“使用这些API”,但实际上并不希望任何人创建另一个提供这些API的服务器。 Because they want to sell Windows to run it! 因为他们想卖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 use the Java EE brand. Sun希望人们使用该语言,因此他们使任何人都可以实现Java EE规范,但他们必须通过Sun(并付费)的严格测试套件才能使用 Java EE品牌。 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. 这导致大量Java EE服务器可用,您通常可以重用核心业务逻辑,但必须配置Java EE服务器以提供应用程序所需的资源。

See http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#Certified_application_servers for the state of servers today. 请参阅http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#Certified_application_servers了解今天的服务器状态。 Both commercial and open source are available based on your needs - pick the one that suits you best. 商业和开源都可以根据您的需求提供 - 选择最适合您的产品。

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,任何人都可以实现,而且它们具有。

First off, you can run .NET code off Apache using mod_mono, so it is not limited to IIS. 首先,您可以使用mod_mono从Apache运行.NET代码,因此它不仅限于IIS。 There are also several other web servers (Cassini and XPS come to mind) that will run ASP.NET as well. 还有一些其他Web服务器(Cassini和XPS可以想到)也将运行ASP.NET。

In order to run a dynamic web application you need both a web server and an application server. 要运行动态Web应用程序,您需要Web服务器和应用程序服务器。 Sometimes these integrate so well they appear to be one and the same, sometimes not. 有时这些整合得很好,它们看起来是同一个,有时不是。

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. 由于.NET和IIS都是来自Microsoft的技术,因此ASP.NET及其应用服务器方面(aspnet_isapi.dll)与IIS捆绑在一起,不同的.NET安装程序与IIS集成。 Of course, Microsoft only implemented it on their OS and for their web server. 当然,Microsoft只在其操作系统和Web服务器上实现了它。

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. Apache通常在Java部署中用作其后面的应用程序服务器的代理,并且可能提供静态内容,或处理SSL以及类似的问题。 It is entirely optional, although there are good reasons to use it. 它完全是可选的,尽管有充分的理由使用它。

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. Tomcat和Jetty基本上是java Web服务器,它提供了一个定义的框架(Servlets等),用于创建带有Java代码的动态Web站点。 They are often components of a larger application server, or can be deployed alone. 它们通常是较大的应用程序服务器的组件,或者可以单独部署。

JBoss is an example of an application server (Glassfish and Weblogic are two very common others), which provides the full J2EE specification. JBoss是应用程序服务器的一个示例(Glassfish和Weblogic是两个非常常见的其他服务器),它提供了完整的J2EE规范。 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. J2EE规范背后的想法是允许以定义的方式构建应用程序服务器,以便可以在符合规范的不同供应商的不同应用程序服务器之间切换应用程序。 The specification is about how to interact with defined services that are useful for server-side program. 该规范是关于如何与对服务器端程序有用的已定义服务进行交互。

Because Java EE is a specification, not a product itself. 因为Java EE是规范,而不是产品本身。 Remember that Java is a lot more open than .NET (In the specification sense). 请记住,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. 差异化是所有应用程序服务器存在的原因,一种规模并不适合所有应用程序服

One reason is that writing a servlet is as easy as implementing the javax.servlet.Servlet interface in a concrete class. 一个原因是编写servlet就像在具体类中实现javax.servlet.Servlet接口一样简单。 Servlet containers, then, only need to support a fairly simple API in order to call themselves web servers. 因此,Servlet容器只需要支持一个相当简单的API就可以自己调用Web服务器。 This makes setting out to develop a servlet container extremely simple because of this limited contract of functionality. 由于这种有限的功能合同,这使得开发servlet容器非常简单。

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. 关闭工具的选择是Java的优点和缺点之一,看看可用的Java Web开发框架,您可以无休止地评估它们来决定。 in .Net it's pretty much MVC. 在.Net中,它几乎就是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. 如果他们需要一个Web服务器和JBoss,如果他们需要一个免费的应用服务器,那么大多数都会去Tomcat。 The reasons for this have already been said, J2EE is a specification. 原因已经说过了,J2EE就是一个规范。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM