Web Container的概念及工作流

一. Web Server,Web Container,Application Container的区别

(该部分转自: http://blog.csdn.net/lingli219/article/details/17025505)

  • Web Server is a server capable of receiving HTTP requests, interpreting them, processing the corresponding HTTP Responses and sending them to the appropriate clients (Web Browsers). Example: Apache Web Server.

         Web server 是指能够接收,解析,处理HTTP请求,并将处理后的结果返回给合适的客户端(比如浏览器)的服务器。例如IHS(IBM HTTP Server)和Apache,IHS是

          建立 在Apahce之上的由IBM添加更多功能后的服务器,都处理HTTP请求(正如IHS名字所显示的 http server)

  • A Web Container is a J2EE compliant implementation which provides an environment for the Servlets and JSPs to run. Putting it differently we can say that a Web Container is combination of a Servlet Engine and a JSP Engine. If an HTTP Request refers to a Web Component (typically a Servlet or a JSP) then the request is forwarded to the Web Container and the result of the request is sent back to Web Server, which uses that result to prepare the HTTP Response for the particular HTTP Request. Example: Tomcat is a typical Web Container. A typical setup would be to have Apache HTTP Server as the Web Server and Tomcat as the Web Container.

        Web容器J2EE标准的实现,为serverlet和jsp提供运行环境。例如,当一个HTTP请求通过要访问一个web组件(通常是一个serverlet或者是jsp),通常是将这个请求转发

        给web container处理完毕后再返回到web server。Tomcat是一个轻量级的web container。

  • An Application Server is a complete server, which provides an environment for running the business components (EJBs, ADF BCs, etc.) in addition to providing the capabilities of a Web Container as well as of a Web Server. Example: Bea WebLogic, IBM WebSphere, Oracle Application Server, etc.

       Application Server: 是一个完整的server,它提供整个业务模块 (EJBs,ADFs,etc)运行的环境。除了单独作为一个web container外,它还能处理HTTP请求(当然

      包括其它协议,比如tcp,消息队列等)。Websphere 和weblogic 都属于此类!

 

二. Web Container 可以做什么?

  1. Communication Support 应用通信支撑

        通过web container,我们不用自己写web scoket去监听服务器端口,创建流等等。

      2. Lifecycle Management 生命周期的管理

       class文件的装载和初始化,servlet 的初始化,调用,垃圾回收等等

     3. 多线程的支持

       容器会自动的为每一个接收到的请求创建一个Java线程去处理它。

     4. 声明式安全处理

        我们可以通过XML配置权限

    5. JSP的支持

       将JSP转化为Servlet

 

三. Web Container 处理请求的过程

     1. 客户端通过浏览器发送请求时,web container会自动为我们创建两个对象: HttpServletRequest 和 HttpServletResponse

     2. 创建一个Thread, 将request和response放到Thread中

     3. 根据请求的方式,进行业务逻辑处理,doGet() / doPost()

     4. 容器将response 对象转化为HttpResponse返回给用户,将线程归还给线程池,并销毁request和response对象

 

      

 

posted @ 2017-02-15 15:37  梅花瘦  阅读(1754)  评论(0)    收藏  举报