标签:
Mapping Requests to Servlets 映射请求到 Servlet
The mapping techniques described in this chapter are required for Web containers mapping client requests to servlets.
Web 容器需要使用本章描述的映射技术将客户端请求映射到 servlet。
12.1 Use of URL Paths 使用 URL 路径
Upon receipt of a client request, the Web container determines the Web application to which to forward it. The Web application selected must have the longest context path that matches the start of the request URL. The matched part of the URL is the context path when mapping to servlets.
The Web container next must locate the servlet to process the request using the path mapping procedure described below.
当接收到一个客户端请求,Web容器确定转发到那个Web应用。必须选择拥有最长上下文路径匹配请求 URL 开始的Web应用。当映射到 servlet 时,URL匹配的一部分是上下文路径。Web容器接下来必须使用下面描述的路径映射过程来定位 servlet 来处理请求。
The path used for mapping to a servlet is the request URL from the request object minus the context path and the path parameters. The URL path mapping rules below are used in order. The first successful match is used with no further matches attempted:
用来映射 servlet 的路径是请求对象的请求URL 减去上下文路径和路径参数。下面的URL映射路径按顺序使用。使用第一个成功的匹配,不会再做更一步的匹配:
The container must use case-sensitive string comparisons for matching.
容器必须使用大小写敏感的字符串比较来匹配。
12.2 Specification of Mappings 映射规范
In the Web application deployment descriptor, the following syntax is used to define mappings:
在 web 应用描述符中,使用下面的语法来定义映射:
12.2.1 Implicit Mappings 隐含映射
If the container has an internal JSP container, the *.jsp extension is mapped to it, allowing JSP pages to be executed on demand. This mapping is termed an implicit mapping. If a *.jsp mapping is defined by the Web application, its mapping takes precedence over the implicit mapping.
A servlet container is allowed to make other implicit mappings as long as explicit mappings take precedence. For example, an implicit mapping of *.shtml could be mapped to include functionality on the server.
如果容器有一个内部的 JSP 容器,*.jsp 扩展名将映射到它,允许根据需要执行 JSP 页面。此映射被称为隐含映射。如果引用定义了 *.jsp 映射,此映射优先于隐含映射。servlet 容器允许其他的隐式映射只要显示映射优先(级更高)。例如,.shtml 的隐式映射可以映射包含服务器上的功能。
12.2.2 Example Mapping Set 映射设置实例
Consider the following set of mappings:
思考下面的映射设置:
TABLE 12-1 Example Set of Maps
表 12-1 映射设置示例:
Path Pattern Servlet
/foo/bar/* servlet1
/baz/* servlet2
/catalog servlet3
*.bop servlet4
The following behavior would result:
以下是映射的结果:
TABLE 12-2 Incoming Paths Applied to Example Maps
表 12-2 入站路径应用到示例中的映射
Incoming Path Servlet Handling Request 处理请求的 Servlet
/foo/bar/index.html servlet1
/foo/bar/index.bop servlet1
/baz servlet2
/baz/index.html servlet2
/catalog servlet3
/catalog/index.html “default” servlet (“默认” servlet)
/catalog/racecar.bop servlet4
/index.bop servlet4
Note that in the case of /catalog/index.html and /catalog/racecar.bop, the servlet mapped to “/catalog” is not used because the match is not exact.
注意 /catalog/index.html 和 /catalog/racecar.bop,映射到 “/catalog” 的 servlet 没有被使用,因为匹配不精确。
第十二章 映射请求到Servlet(JavaTM Servlet 规范3.1 )
标签:
原文地址:http://www.cnblogs.com/whilliy/p/5700718.html