Servlet 3.1规范 Overview

1.1 What is a Servlet?
什么是Servlet
A servlet is a Java? technology-based Web component, managed by a container, that 
servlet是基于JAVA的web组件,由servlet容器管理,生成动态内容
generates dynamic content. Like other Java technology-based components, servlets 
像其他基于Java技术组件一样,
are platform-independent Java classes that are compiled to platform-neutral byte 
Servlet是与平台无关的Java类被编译成与平台无关的字节servlet代码,
code that can be loaded dynamically into and run by a Java technology-enabled Web 
可以动态加载和运行由Java技术的Web服务器
server. Containers, sometimes called servlet engines, are Web server extensions that 
servlet容器有时被称为servlet引擎,是扩展了提供servlet功能的Web服务器。
provide servlet functionality. Servlets interact with Web clients via a 
Servlet和Web客户端交互是通过servlet容器的请求响应模式实现的
request/response paradigm implemented by the servlet container. 


1.2 What is a Servlet Container?
什么是Servlet Container
The servlet container is a part of a Web server or application server that provides the 
servlet容器是提供了网络服务请求和发送响应,急吗MIME请求,并给予MIME的格式回应的
network services over which requests and responses are sent, decodes MIME-based 
Web服务器或者应用服务器的一部分
requests, and formats MIME-based responses. A servlet container also contains and 
servlet容器也包含而且管理servlet的生命周期
manages servlets through their lifecycle.


A servlet container can be built into a host Web server, or installed as an add-on 
servlet容器可以再主机的Web服务器构建,
component to a Web Server via that server’s native extension API. Servlet containers 
或者通过该服务器的本机API的扩展安装到Web服务器的一个附加组件
can also be built into or possibly installed into Web-enabled application servers.
Servlet容器可以被内置或者被安装在Web应用服务器中
All servlet containers must support HTTP as a protocol for requests and responses, 
所有的servlet容器不但需要支持HTTP请求响应协议
but additional request/response-based protocols such as HTTPS (HTTP over SSL) 
而且还要支持请求响应协议,如HTTPS(SSL上的HTTP)
may be supported. The required versions of the HTTP specification that a container 
所需版本的HTTP规范中指明servlet容器需要实现HTTP/1.0和HTTP/1.1
must implement are HTTP/1.0 and HTTP/1.1. Because the container may have a 
在RFC2616中描述由于servlet容器可能需要一个缓存机制
caching mechanism described in RFC2616 (HTTP/1.1), it may modify requests from
它可能在传递到servlet中之前修改来自客户端的请求
the clients before delivering them to the servlet, may modify responses produced by 
在放松到客户端之前修改servlet产生的响应
servlets before sending them to the clients, or may respond to requests without 
按照RFC2616中的要求,他可以在不经过servlet就对一个请求做相应。
delivering them to the servlet under the compliance with RFC2616.


A servlet container may place security restrictions on the environment in which a 
servlet容器对servlet的执行需要有安全的环境限制
servlet executes. In a Java Platform, Standard Edition (J2SE, v.1.3 or above) or Java 
在Java中J2SE1.3以上或者JAVA EE1.3以上的环境
Platform, Enterprise Edition (Java EE, v.1.3 or above) environment, these restrictions 


should be placed using the permission architecture defined by the Java platform. For 
这些限制应放在Java平台的使用权限定义的架构。
example, high-end application servers may limit the creation of a Thread object to 
比如高级的应用服务器需要创建一个Thread来保证其他的servlet容器的组件
insure that other components of the container are not negatively impacted.
不会受到负面影响。
Java SE 7 is the minimum version of the underlying Java platform with which servlet 
Java SE 7 servlet容器所构建的最低版本
containers must be built. 


1.3 An Example
实例
The following is a typical sequence of events:
以下是典型的一些列事件
1. A client (e.g., a Web browser) accesses a Web server and makes an HTTP request. 
一个客户端(浏览器)向Web 服务器发送了一个HTTP请求
2. The request is received by the Web server and handed off to the servlet container. 
Web服务器接收到请求然后移交给servlet容器
The servlet container can be running in the same process as the host Web server, 
servlet容器可以在Web服务器的同一个处理中运行
in a different process on the same host, or on a different host from the Web server 
在同一个主机的不同处理中运行,
for which it processes requests.
或在不同主机上的Web服务器它处理的请求。(集群?)


3. The servlet container determines which servlet to invoke based on the 
servlet容器由配置决定调用哪里一个servlet
configuration of its servlets, and calls it with objects representing the request and 
然后传入Request和Response对象
response. 


4. The servlet uses the request object to find out who the remote user is, what HTTP 
servlet可以在Request对象中找到到远程用户信息,
POST parameters may have been sent as part of this request, and other relevant 
传递的参数和相关数据
data. The servlet performs whatever logic it was programmed with, and generates 
该servlet执行任何逻辑编程,并生成数据发送回客户端
data to send back to the client. It sends this data back to the client via the 
他通过Response把数据返回到client中
response object.


5. Once the servlet has finished processing the request, the servlet container ensures 
一旦servlet完成对Request的处理,servlet容器确保响应发送
that the response is properly flushed, and returns control back to the host Web 
并把控制权交回到Web服务器中
server.


1.4 Comparing Servlets with Other Technologies
Servlet与其他技术对比
In functionality, servlets lie somewhere between Common Gateway Interface (CGI) 
在功能上,servlet基于CGI和Netscape Server API之间
programs and proprietary server extensions such as the Netscape Server API 


(NSAPI) or Apache Modules.


Servlets have the following advantages over other server extension mechanisms:
servlet有以下的优势
■ They are generally much faster than CGI scripts because a different process model 
servlet运行效率比CGI脚本快,因为使用不同的处理模型
is used.


■ They use a standard API that is supported by many Web servers.
servlet使用由不同的Web服务器支持的统一API
■ They have all the advantages of the Java programming language, including ease 
servlet有Java语言的一切优势,包括容易开发,跨平台
of development and platform independence.


■ They can access the large set of APIs available for the Java platform.
servlet可以使用Java平台中的大量可用API
1.5 Relationship to Java Platform, Enterprise Edition
与JAVA EE的关系
The Java Servlet API v.3.1 is a required API of the Java Platform, Enterprise Edition, 
Java Servlet API 3.1版本需要Java平台,企业版7.1
Servlet containers and servlets deployed into them must meet additional 
Servlet容器和servlet部署到他们必须满足其他
requirements, described in the Java EE specification, for executing in a Java EE 
在Java EE规范,在Java EE要求和环境中执行。
environment.


1. Please see the Java? Platform, Enterprise Edition specification available at 


http://www.oracle.com/technetwork/java/javaee/tech/index.html4 Java Servlet Specification ?


1.6 Compatibility with Java Servlet Specification Version 2.5
Servlet与2.5版本的兼容性
1.6.1 Processing annotations
处理注解
In Servlet 2.5, metadata-complete only affected the scanning of annotations at 
在2.5中,metadata-complete只有在部署中才会影响扫描annotations
deployment time. The notion of web-fragments did not exist in servlet 2.5. However 
而且不存在Web片段的概念
in servlet 3.0 and later, metadata-complete affects scanning of all annotations that 
而在3.0版本之后metadata-complete在
specify deployment information and web-fragments at deployment time. The 
(我也不懂什么意思)
version of the descriptor MUST not affect which annotations you scan for in a web 
解释的版本必须不能影响在web应用中扫描到的annotation
application. An implementation of a particular version of the specification MUST 
一个实现了特别版本的规范必须要扫描所有的支持的annation
scan for all annotations supported in that configuration, unless metadatacomplete is specified.
除非metadata-complete已经指明。
Servlet3.1规范(最终版) JavaTM Servlet 规范 版本 3.1(最终版) Shing Wai Chan Rajiv Mordani [作者] 穆茂强 张开涛 [译者] 2012年6月翻译 2013年7月修订 目录 前言 ............................... 3 其他资料 ............................................................................................................................................................ 3 谁应该读此规范 ................................................................................................................................................ 3 API规范 ............................................................................................................................................................3 其他的 Java 平台规范 ....................................................................................................................................... 3 其他重要参考资料 ............................................................................................................................................ 4 提供反馈 ............................................................................................................................................................ 4 专家组成员 ........................................................................................................................................................ 5 答谢 .................................................................................................................................................................... 5 目录 ............................... 6 概览 .............................. 13 1.1 1.2 1.3 1.4 1.5 1.6 什么是 Servlet? .................................................................................................................................. 13 什么是Servlet容器?...............................................................................................................................13 例子...........................................................................................................................................................13 Serv
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值