1.Containers
又名
Servlet Engines,
是对
Web
服务器的扩展,提供了
servlet functionality.
2.Servlet Containers
是
web
server
或
application server
的部分,它负责发送
requests/responses
,decodes
MIME-based requests,
format MIM-based responses
,同时管理
Servlet
、
Filter
的生命周期。
3.Servlet :
由容器根据其配置来调用,
Servlet
只负责处理
requests/responses
,根据请求输出响应。
Servlet Mapping
的匹配顺序或优先级如下:
1
)
t
he
exact match
精确匹配(完全一样)
:
除了下面红色
字体列出的情况外的,均认为是精确匹配。
2
)
the longest path
match
最长
路径匹配
所有以“
/
”
开始
以“
/*
”
结束
的用做路径匹配,匹配时选择最长的
3
)
the
extension
match
扩展匹配
所有以
“
.*
”
开始
的,用于扩展匹配
4
)如果前三种都不匹配,则容器将其作为
resource
访问处理。如果定义了默认的
Servlet
,则采用默认的
Servlet
处理请求。
仅包含“
/
”
字符串的,用于默认
Servlet
匹配
5
)所有匹配都大小写敏感。
4.Servlet 3.0
引进了处理异步请求的机制
。
5.Request:
每个
request
对象只在
servlet
的
service
方法或
filter
的
doFilter
方法内有效(处理异步请求除外)。
6.
requestURI
=
contextPath
+ servletPath + pathInfo
servletPath 根据Servlet
Mapping获得。
Context Path
对应一个
web
应用,如每个
war
包就定义了一个
Context
path.
每个
path
如果不为空则以‘
/
’开始,而不以‘
/
’结束。
7.Servlet Context
:
定义了
Servlet
可以看到的路径或者参数等,与
Web
应用一一对应。
The ServletContext interface defines a
servlet’s view of the Web application within
which the servlet is
running.
Using the
ServletContext object, a servlet can log
events, obtain URL references to resources,
and set and store attributes that other servlets in the context(同一
Context
) can access.
A ServletContext is rooted at a known
path within a Web server. For example, a
servlet context could
be located at http://www.mycorp.com/catalog
.
All requests
that begin with the
/catalog request path, known as the context path, are routed to
the Web application
associated with the ServletContext.
每个
Web
应用只有一个ServletContext
,它是单例的
。它提供了配置方法可供调用,但所有的配置方法只在contextInitialized事件发生时有效,其它地方调用这些方法都是非法的。
ServletContext
提供了对其路径下所有资源的访问(静态)对资源的访问通过调用getResource
或getResourceAsStream。如getResource("/index.jsp")只返回
index.jsp
的代码,不会对其处理。
The full listing of
the resources in the Web application can be accessed using the
getResourcePaths(String
path) method.
Servlet contexts can
not be shared across virtual hosts.
Servlet contexts
临时工作目录可以通过javax.servlet.context.tempdir获得。
8.Response:
对象封装了所有要返回客户端的信息,出于有效性,一般
Container
会缓存到
client
的输出。
9.Filter
:
官方定义:A filter is a
reusable piece of code that can transform the content of HTTP
requests,responses, and header information.
Filter
通常不会创建
Response
或像
Servlet
一样处理响应请求,他们只对请求或响应做适当的修改(
they modify or adapt the requests for a
resource, and modify
or adapt responses from a resource).
Examples of
Filtering Components
■ Authentication
filters
■ Logging and
auditing filters
■ Image conversion
filters
■ Data compression
filters
■ Encryption filters
■ Tokenizing filters
■ Filters that
trigger resource access events
■ XSL/T filters that
transform XML content
■ MIME-type chain
filters
■ Caching filters
Filter Chain
可以调用
Filter
或
servlet
,最后调用的肯定是
Servlet
或
JSP
。
整个FilterChain的调用(包括了对Servlet的调用)可以想象成是堆栈方式的,每doFilter()
一次就压栈一次,而栈顶肯定是Servlet或JSP,Servlet将响应输出,然后就是每个Filter出栈,做一些其他的事情。
Servlet
的响应方式不会改变,它按传进的Re
sponse
响应。
Servlet
的输出直接发往客户端。而每个
Filter
里
在
doFilter()
方法后,再处理
Response
是没有用的,只是用来做
些扫尾工作,比如释放引用的资源。
do
Filter
方法的代码:
servlet 3.0
规范对
doFilter
的实现模式进行了描述,供分为
8
步,开发者可以根据需要只选择其中的部分步骤。
Public void doFilter(request,resp0nse,chain){
//
处理
request
,可以对
request
处理
,response
做包装等,后续的
filter
或
servlet
或
jsp
得到的是包装或处理
//
后的。
…...
chain
.doFilter(request,reponse)
//
扫尾工作
…..
}
Filter
也可以处理
request-dispatched:
10.Session
:
跟踪客户端信息:
1
)
Coo
kies
2) URL Rewriting
3)
SSL Sessions
11.
Dispatching
Requests
When building a Web
application, it is often useful to forward processing of a
request to another
servlet, or to include the output of another servlet in the response.
RequestDispatcher
通过调用
ServletC
ontext.getRequestDispatcher(path)获得。
The RequestDispatcher
interface provides a mechanism to accomplish this.
To use a request
dispatcher, a servlet calls either the include method or forward
method of the
RequestDispatcher interface.
12.
The
application events
The application
events facility gives the Web Application Developer greater control
over the lifecycle of
the ServletContext and HttpSession and ServletRequest,
allows for better
code factorization, and increases efficiency in managing the
resources that the
Web application uses.
分享到:
- 2009-03-06 20:39
- 浏览 1294
- 评论(0)
- 论坛回复 / 浏览 (0 / 2753)
- 查看更多
相关推荐
根据提供的文件内容,以下是对Servlet3.1规范官方文档(中文版)中的知识点的详细说明。 首先,Servlet3.1官方文档是Java™ Servlet规范版本3.1的中文翻译版本。它详细描述了servlet技术规范的各个方面,包括对...
Servlet3.1规范是Java服务器端编程的重要里程碑,它在原有的Servlet技术基础上进行了多项改进和扩展,极大地提升了Web应用的性能和开发效率。这个规范主要关注于Servlet、过滤器(Filter)和监听器(Listener)的...
很多人在学习Spring+struts2+hibernate或者现在比较流行的Spring+Spring MVC + Mybatis的时候跟我一样忽略的web的基础,基础未打实,就开始冒进,导致后面的学习很多地方模模...无论是什么框架Servlet仍旧是下层建筑。
这个规范由Java Community Process (JCP)制定,并由Sun Microsystems(现为Oracle Corporation)首次发布,现在已经发展到Servlet 4.0版本。在本文中,我们将深入探讨Servlet规范的关键知识点,以及它如何提升Java ...
### Servlet规范概览 《Java™ Servlet Specification》是Sun Microsystems公司发布的一份重要技术文档,主要阐述了Servlet规范的版本2.3。该规范详细介绍了Servlet接口、生命周期、配置及部署等方面的内容,为Web...
这个规范是Java Servlet API的一部分,由Java Community Process (JCP)制定,并且在Java EE 7中被引入。在Servlet3.1版本中,有许多增强和新特性,使得Web开发更为灵活和高效。 首先,Servlet3.1引入了异步处理能力...
### Servlet 3.1 规范详解 #### 一、概述 Servlet 技术是 Java 平台中用于构建 Web 应用程序的核心组件之一。Servlet 3.1 规范作为 Java EE 7 或更高版本平台的一部分,代表了 Servlet 技术发展的最新成果。本规范...
Servlet3.1规范是Java Web开发中的一个重要里程碑,它为Java服务器端编程提供了更高效、更灵活的框架。这个规范的中文版对于中国开发者来说,无疑是一个宝贵的资源,可以帮助他们更好地理解和应用Servlet技术。 ...
Servlet 2.4 规范是Java Web开发中一个重要的里程碑,它定义了Servlet和Java服务器页面(JSP)的标准,使得开发人员可以构建可移植的、基于Web的应用程序。以下是对Servlet 2.4规范的详细解读: 1. **概述** - **...
Servlet3.1规范是Java Servlet技术的一个版本,它在Java EE平台中扮演着重要的角色。Java EE(Java Platform, Enterprise Edition)是一个为开发企业级应用提供的平台,而Servlet是Java EE技术中用于处理Web请求的...
### Java Servlet规范版本3.1概述 Java Servlet 3.1规范是Java Servlet API标准的一个版本,它为Java Servlets提供了一个完整和清晰的解释。该规范的目的是定义Java Servlets的API,包括其中的类、接口和方法签名,...
Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范
在JSR-315(JavaTM Servlet 3.0 API Specification)中,专家小组对这项规范进行了详尽的定义和解释。这个规范PDF文件是开发人员深入理解Servlet 3.0的核心资源,同时包含的javadoc为开发者提供了API的详细文档,...
Servlet3.1规范是Java Web开发中的一个重要里程碑,它在Servlet3.0的基础上引入了许多增强功能,提高了Web应用的性能和可扩展性。这个中文最终版的文档为开发者提供了全面的指南,帮助他们理解并利用这些新特性进行...
本文将详细解析JSP和Servlet的相关规范,以及与它们密切相关的EL(Expression Language)和JavaBeans规范。** **1. JSP规范** JSP是一种用于创建动态网页的技术,它允许开发者在HTML页面中嵌入Java代码。在JSP 2.0...
Servlet 2.3 规范是Java服务器端编程的重要指南,它定义了Servlet API的版本,这个API使得开发者能够创建动态、交互式的Web应用程序。在Servlet 2.3规范中,我们能找到许多关键知识点,包括但不限于以下几个方面: ...
Servlet 3.0是Java EE 6规范的一部分,它对原有的Servlet API进行了重大改进和扩展,为Web开发提供了更高效、灵活和强大的功能。在这个最新的规范中,开发者可以享受到一系列新特性和改进,使得构建动态Web应用变得...
以下是Servlet3.1规范中的关键知识点: 1. **异步处理**: Servlet3.1引入了异步Servlet,允许在处理请求时返回控制权给容器,然后在后台执行长时间运行的操作。这改善了性能,因为线程不再被阻塞,可以处理其他...
Servlet 3.1规范是Java Web开发中的一个重要里程碑,它扩展并增强了原有的Servlet技术,提供了更高效、更灵活的Web应用程序开发能力。这份规范的最终版包括了中英双语版本,使得开发者无论语言背景如何,都能更好地...