JAVA服务器概述

Java服务器

  做为Java工程师,服务器对于咱们的开发工做很重要,将咱们开发好的项目放到服务器上用户才可使用。咱们经常使用到的服务器有Tomcat、Apache、Nginx等等。对于咱们所开发的应用,如何选择合适的服务器是个问题。下面简单的介绍Web服务器Servlet容器应用服务器的基本概念以及各类服务器的应用场景。
  本文是Google上查询的几遍文章的部分截断,我本身加上了中文翻译。html

WEB Server

Example

  Apache、IIS、Nginxjava

Features and Responsibility

  Web Servers are responsible for serving static content e.g. HTML over HTTP protocol.
  Web服务器的主要职责是服务静态页面,例如,以HTTP协议传输的HTML页面web

  In a simple situation,a user type in a URL in browser(a client),and get a web page to read.So what the server does is sending a web page to the client.The transformation is in HTTP protocol which specifies the format of request and response message.
  一个简单的应用场景,用户在浏览器(客户端)输入URL而且开始浏览网页。那么服务器所作的就是发送一个静态页面到客户端,传输的信息是经过指定了请求和响应格式的HTTP协议。
webserver.jpg数据库

Servlet Container

Example

  Tomcat、Jetty浏览器

Features and Responsibility

  A servlet-container supports only the servlet API(including JSP,JSTL)
  Servlet容器仅仅支持Servlet API,包括JSP、JSTL安全

  Servlet container are only responsible for generating HTML by executing JSP and Servlet on Server side.So servlet container is essentially a part of a web server that interacts with the servlets.
  Servlet容器惟一的职责就是经过执行服务器上的JSP和Servlet来产生HTML页面。那么Servlet容器本质上是Web服务器的一部分,只不过加上了和Sevlet交互的接口。
ServletContainer.jpg服务器

Servlet

  Servlet is an interface defined in javax.servlet package.It declares three essential methods for the life cycle of a servlet – init(),service(),and destroy().They are implemented by every servlet and invoked at specific times by the server.
  Servlet是定义在javax.servlet包下面的接口。对于一个Servlet的声明周期,它声明了三种内在的方法——init(),servie()和destroy().在服务器上每个Servlet被唤醒的时候,他们都会执行。app

How Servlet Container and web server process a request ?ide

  1. Web server receives HTTP request
  2. Web server forwards the request to servlet containter
  3. The servlet is dynamically retrieved and loaded into the address space of the container,if it is not in the container.
  4. The container invokes the init() method of the servlet for initialization(invoked once when the servlet is loaded first time)
  5. The container invokes the service() method of the servlet to process the HTTP request,read data in the request and formulate a response.The servlet remains in the container’s address space and can process other HTTP requests.

Servlet.jpg

Application Server

Example

  WebSphere,WebLogic,JBossui

Features and Responsibility

  Application Server is responsible for generating dynamic content by executing server side code e.g. JSP,Servlet or EJB.
  应用服务的主要职责就是经过执行服务器代码产生动态页面,列如,JSP,Servlet或者EJB。

  Application server is responsible for serving dynamic content,managing EJB pool,facilitating distributed transation,facilitating application lookup over JNDI,application security and others.
  应用服务器的主要任务是服务动态内容,管理EJB Pool,促进事务分配,促进应用查找JNDI,应用安全等等。

  An application server supports the whole JavaEE - EJB,JMS,CDI,JTA
  应用服务器支持整个JavaEE体系
  An application usually includes a Web server,but also adds a lot of more features.The most important is that it manages objects.Whether they will be Servlets,EJBs,JMS listenters.
  一个应用服务器一般包括一个Web服务器,可是额外加了不少特性。最重要的就是它管理对象(Servlets,EJB,JMS)

Tomcat

  Tomcat is not exactly an application server, it's more of a servlet engine or web container or also known as servlet containers because it provides the runtime environment for Servlet and JSP but doesn't provide the services like EJB and distributed transaction which are a key feature of the application server in Java JEE world
  Tomcat不彻底是一个应用服务器,它只是一个Servlet引擎或者是一个Web容器或者是咱们众所周知的Servlet容器,由于它只提供了Servlet和JSP的运行环境,可是没有提供像是EJB和事务控制的部分,而这部分才是JEE领域里面应用服务器的特色。

Summary

  It’s expected from a Web server to provide HTTP protocol level service while application server is supposed to provide more powerful and dynamic Web service and business level service via EJB(Enterprise Java Beans).Essential services like Database connection pooling is not only provided by application server but also by Servlet containers like Tomcat.
  能够预计的是一个Web服务器提供HTTP协议层次的服务,应用服务器应该是提供更多的强大的动态的Web服务,而且包括商务级别的服务经由EJB。像数据库链接池这样必要的服务不单单是应用服务器支持,像是Tomcat这样的Servlet容器也支持。

  You need a Web server like Apache HTTPD if you are serving static web pages.If you have a Java application with just JSP and Servlet to generate dynamic content then you need Servlet containers like Tomcat or Jetty while,if you have JavaEE application using EJB,distributed transation,messaging and other fancy features than you need a full fledged application server like JBoss,WebSphere or WebLogic.
  若是你为静态页面提供服务,你就须要像Apache HTTPD这样的Web服务器。若是你有一个仅仅是JSP和Servlet的JAVA应用去生成动态的页面内容,你须要一个像Tomcat或者Jetty这样的Servlet容器。若是你的JAVAEE应用使用了EJB,事务管理,消息和其余一些复杂华丽的特色,你就须要一个彻底成熟的应用服务器,列如JBoss,WebSphere或者WebLogic.

  For example,one of the popular setups is Apache fronting Tomcat or Ngnix fronting Tomcat
  好比,一个很是流行的作法就是在Tomcat上面加一Apache或者是在Tomcat上加Nginx服务。

  What is the difference between application server and web server ?

  Web Server is designed to serve HTTP Content. Application Server can also serve HTTP Content but is not limited to just HTTP. It can be provided other protocol support such as RMI/RPC
  Web服务器旨在为HTTP内容提供服务。应用服务器也能够为HTTP内容提供服务,可是它不单单限于HTTP,它能够提供其余的协议支持,例如RMI/RPC。

  Web Server is mostly designed to serve static content, though most Web Servers have plugins to support scripting languages like Perl, PHP, ASP, JSP etc. through which these servers can generate dynamic HTTP content.
  尽管大多数的Web服务器有支持脚本语言的插件,经过这些脚本语言,好比PHP,ASP,JSP,能够产生动态的HTTP内容,可是Web服务器大多数旨在为静态页面服务。

  Most of the application servers have Web Server as integral part of them, that means App Server can do whatever Web Server is capable of. Additionally Application Server have components and features to support Application level services such as Connection Pooling, Object Pooling, Transaction Support, Messaging services etc.
  大多数的应用服务器都包括Web服务器来构成他们完整的体系,这也就意味着应用服务器能够作任何Web服务器有能力作的事情。除此以外,应用服务器包含了一些可以达到应用层次的组件和特色,例如链接池,对象池,事务支持,消息服务等。

  As web servers are well suited for static content and app servers for dynamic content, most of the production environments have web server acting as reverse proxy to app server. That means while service a page request, static contents such as images/Static html is served by web server that interprets the request. Using some kind of filtering technique (mostly extension of requested resource) web server identifies dynamic content request and transparently forwards to app serve  对于静态页面来讲Web服务器很适,而应用服务器适合动态内容,可是大多数的生产环境都是有一个Web服务器做为应用服务器的反向代理。这就意味着一个页面的请求,像图片和静态HTML这样的静态内容是由Web服务器提供服务。使用一些像过滤器这样的技术,Web服务器鉴别动态内容请求并显示的导向应用服务器。

相关文章
相关标签/搜索