什么是j2ee中的web容器

http://www.servletworld.com/servlet-tutorials/j2ee-web-container-introduction.html

Introduction to web containers

 介绍web容器
## Overview of web containers: This tutorial provides the basic introduction to J2EE web containers (Also called **Servlet container** or**Servlet engine**). 这个教室讲了在j2ee中web容器到底是一个什么样的东西,web容器也称作是servlet容器或者servlet的引擎. In J2EE architecture the basic purpose of the container is to provide the runtime environment for the components. components are managed by container, in order to be managed by container components must follow certain contract. J2EE specification defines contract between components and container, and specifies the deployment model for components. Contract specifies how components should be developed and deployed, and how components can access services provided by container. When developing applications with J2EE, we develop components that follow the contract defined in the specification. 在j2ee架构中,容器的基本功能就是提供一个运行时的环境给组件,同时管理这些组件,为了实现管理这些组件,指定一些规约.j2ee定义了一些在容器和组件之间的规约,同时还定义了组件的开发部署模型.规约定义了组件怎么样来被开发以及部署.还有就是组件怎么通过容器来被访问到来提供服务.当在部署j2ee的应用时,必须遵循这些规约. In J2EE this contract is specified in term of various interfaces and classes, developer writes the classes that implements this interfaces or extends the classes and provides appropriate implementation of various methods and rest will be done by container. Container takes the responsibility of instantiating, initializing and invoking the components. Application does not directly instantiate or invokes components. As you will see that application never instantiate an object of servlet or call any of the init(), service() or destroy() life cycle method, all of these is handled by web container. Web container automatically instantiates and initializes the Servlets on application startup or when invoked for the first time. Container calls the service() method when user requests the servlet. 在j2ee中,这个规约定义了一系列的多种接口和类,开发者需要实现这些接口,或者继承那些类来提供合适的实现方法,之后剩下的事情就有容器来完成.容器负责实例化初始化调用这些组件,应用不需要自己来做这些事情.正如你所看到的,应用不会自己来调用例如init方法,或者service()或者destroy()方法.所有的这些都是有容器来完成.容器会自动的实例初始化这些servlet在程序启动的时候,或者在第一次调用的时候,日期会调用service()方法在他第一次被请求的时候. > **The web container is a Java runtime environment which is responsible for managing life cycle of JSP pages and Servlets**. > web容器就是一个java运行时环境,负责来管理servlet和jsp页面的生命周期. A web container is responsible for instantiating, initializing and invoking Servlets and JSP pages. The web container implements Servlet and JSP API and provide infrastructure for deploying and managing web components. The web container is part of web server or application server that provides the network services over which request and response are sent. A Web container is may be built into the web server or it may be installed as an additional component to a web server. As per the specification, all web containers must support HTTP protocol however it may support addition protocols like HTTPS. 一个web容器就是来负责实例化初始化或者调用servlet和jsp,web容器实现了servlet和jsp api,提供一个部署和管理他们的平台.容器就是web服务器的一部分.或者就是一个应用服务器,来提供网络服务,接受请求响应请求.一个web容器可以被内置在一个web服务器中,或者作为一个单独的组件添加到web服务器中,所有的web容器必须支持http协议,甚至是其他的协议比如https. Web container is also called servlet container or servlet engine. We will use Tomcat throughout all the tutorials. Tomcat is an open source web server, which is the web container reference implementation. You can find more information about tomcat at [http://tomcat.apache.org/](http://tomcat.apache.org/ "Apache Tomcat project Home"). If you have not already downloaded and installed Tomcat, read this tutorial [Setting up a Servlet development environment](http://www.servletworld.com/servlet-tutorials/setup-servlet-development-environment.html "Setup a servlet development environment tutorial")which explains how to install tomcat and setup the environment. We will need to setup the development environment to run the various examples and code sameples given throughout the tutorials. web容器同样被称作是servlet容器或者servlet引擎,我们的教程中都是在使用tomcat来作为web容器.它是一个开源的web服务器.他实现了web容器的定义.可以在这里找到很多的信息.如果还有下载安装它,就去这里看看怎么配置这个环境.我们很多例子需要开发环境来运行. > **Note:** Servlets and JSP pages are collectively called web components. > > 注意,servlet和jsp页面都被称作是web组件.