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
- 浏览 1259
- 评论(0)
- 论坛回复 / 浏览 (0 / 2718)
- 查看更多
相关推荐
很多人在学习Spring+struts2+hibernate或者现在比较流行的Spring+Spring MVC + Mybatis的时候跟我一样忽略的web的基础,基础未打实,就开始冒进,导致后面的学习很多地方模模...无论是什么框架Servlet仍旧是下层建筑。
Servlet3.1官方文档翻译版本,详细描述sevlet技术规范的方方面面......
servlet2.3规范中文版, 关于servlet2.3的规范全面的描述。不是API文档。
Servlet3.1规范中文最终版,可以参考实现Servlet异步请求与回调机制
sun公司出版的Servlet规范
Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范Servlet2.5规范
Servlet3.1规范(最终版).pdf。先找到规范在安装规范去开发,没毛病
Servlet3.1规范(最终版).中文,高清PDF版本,此文档是 Java Servlet 规范,版本:3.1。
servlet2.4 中文 规范 1至12章
servlet最新规范,目前处于早期草案阶段,目标是在Java EE 7或更高平台。
这个是Servlet最新版本API的翻译版本,最大的改变是新增了异步Servlet,希望共同学习!
servlet2.3规范中文版servlet2.3规范中文版.zip
此文档是Java Servlet规范,版本:3.1。此文档描述了Java Servlet API标准。
servlet2.3规范(中文),servlet2.3规范用到了一下的一些规范:J2EE、JSP1.1、JNDI 在14章中讲述了规范中的所有的classes类或接口(改文中不讲述)。对开发者而言以下的有些相关的 协议:URI、URL、HTTP/1.0、MIME...
Servlet3.1规范翻译版本 Servlet3.1(JSR340)规范目前处于早期草案阶段,目标是在Java EE 7或更高平台。 Servlet3.0(JSR 315)已经包含在Java EE 6 平台。
学习javaweb规范的必备文档 提升javaweb设计思想 深入理解javaweb的设计原理
JSP&Servlet;相关的规范
最新发布的servlet-3.0规范,pdf格式。
Servlet3.1规范(英文).pdf
Servlet3.1规范(最终版)高清-完整-目录Servlet3.1规范(最终版)高清-完整-目录