写web.xml时servlet-mapping都是随意些,终于遇到了问题,研究下

How is servlet mapping defined?

servlet映射是如何定义的?

Servlets should be registered with servlet container. For that, you should add entries in web deployment descriptor web.xml. It is located in WEB-INF directory of the web application.
Entries to be done in web.xml for servlet-mapping:
servlets应该被注册在servlet容器中,为了达到这个目的,需要在web部署描述符web.xml中添加servlets。它位于WEB-INF目录,下面是映射需要的组件:
<servlet-mapping>
<servlet-name>milk</servlet-name>
<url-pattern>/drink/*</url-pattern>
</servlet-mapping>
servlet-mapping has two child tags, url-pattern and servlet-name. url-pattern specifies the type of urls for which, the servlet given in servlet-name should be called. Be aware that, the container will use case-sensitive for string comparisons for servlet matching.
servlet-mapping有两个子标签,url-pattern和servlet-name,url-pattern定义哪些url需要调用servlet-name中定义的servlet,url比较是区分大小写的。
Syntax for servlet mapping as per servlet specification SRV.11.2:
SRV.11.2规范中定义的映射语法:
A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.
A string beginning with a ‘*.’ prefix is used as an extension mapping.
A string containing only the ‘/’ character indicates the “default” servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
All other strings are used for exact matches only.
以'/'开头,‘/*’结尾的字符串
以‘*.’开头的字符串
‘/’表示默认servlet
其他字符串都用于精确匹配
(注:/**/*.action是非法的,看了这个才明白)
Rule for URL path mapping:
URL路径映射的规则:
It is used in the following order. First successful match is used with no further attempts.
使用下面的顺序,第一个匹配后不再继续
1. The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the ’/’ character as a path separator. The longest match determines the servlet selected.
3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last ’.’ character.
4. If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a “default” servlet is defined for the application, it will be used.
1. 精确匹配
2. 尽量匹配最长的前缀
3. 如果url包含扩展(例如.jsp),容器会寻找处理这个扩展的servlet,扩展是url最后一段的.之后的字符
4. 如果前三个没有匹配,寻找适合的内容,如果定义了默认servlet,会使用它。

转载于:https://blog.51cto.com/yingtju/758285

Servet映射规范翻译相关推荐

  1. servlet3.1规范翻译:第13章 安全

    servlet3.1规范翻译:第13章 安全 2013-02-21 16:55 1563人阅读 评论(0) 收藏 举报  分类: servlet3.1规范翻译(17)  目录(?)[+] 第13章 安 ...

  2. java 可插拔注解_servlet3.1规范翻译:第8章 注解和可插拔性

    servlet3.1规范翻译:第8章 注解和可插拔性 . 这是Servlet3.0的新特性之一:这是Servlet3.0的新特性之一: 通过Annotation(注解)配置Servlet之前版本的Se ...

  3. MBTiles 1.2 规范翻译

    MBTiles 1.2 可以参考超图的文档MBTiles扩展 具体实现可以参考浅谈利用SQLite存储离散瓦片的思路和实现方法 mapbox提供了一个简单实现测试代码,github地址在这里https ...

  4. 3gpp协议_春天工作室lt;3GPP规范翻译系列gt;1:TS37340协议翻译(导读)第一部分...

    作者介绍:火狐(笔名),无线技术专家,春天工作室黄埔培训学员,出于工作需要和个人兴趣爱好,利用业余时间学习5G(NR).为了方便更多读者进行学习和阅读,作者完成了本规范的翻译.春天哥,国内知名移动通信 ...

  5. servlet3.1规范翻译:前言

    应朋友之邀(博客地址:http://jinnianshilongnian.iteye.com/),一起翻译servlet3.1规范,本人不才,英语水平有限,勉强而为之.翻译过程中有很多地方把握不准确, ...

  6. aplus翻译_promise/A+规范翻译以及手写实现

    如果要手写实现promise,那么先看看promise/A+规范,再来实现,将会事半功倍. 那么我先翻译一下Promise/A+规范中的内容. 术语 1.1 promise 是一个带有符合此规范的th ...

  7. EPP-域名注册局宽限期映射(RFC3915翻译)

    文章目录 1. 引言 1.1 文档的约定 2. 赎回宽限期状态图 3. 对象属性 3.1 状态值 3.1 注册数据和辅助信息 3.2 日期和时间 3.3 客户端声明 4. EPP命令映射 4.1 EP ...

  8. MMS规范翻译(MMS Architecture Overview)

    WAPTM MMS Architecture Overview Version 25-April-2001 无线应用层协议 多媒体消息服务 框架总览规范 译者:一切皆有可能 Mail:tomorrow ...

  9. java+mysql 实现实体的映射与翻译

    文章目录 一.定义注解 二.注解处理器 三.工具类 四.测试类 完善<java高级程序设计>中第四章注解的4.5实例 通过扫描指定路径下的所有类,找到含有指定注解的实体,解析这些实体,并生 ...

最新文章

  1. Oracle note 基礎入門篇1
  2. 2010年8月blog汇总:敏捷个人和OpenExpressApp之建模支持
  3. 中国万网域名注册量动态:12月上旬净增8424个
  4. 有窗体和无窗体覆盖的问题
  5. MONO Design创建电信3D机房
  6. C++实现大数据乘法
  7. (二分+区间搜索 )Mountain Walking(poj2110/poj2922)
  8. Java 算法 幂方分解
  9. oracle 创建视图、修改视图、删除视图、利用视图操作基本表
  10. xp 无法用计算机名访问,WinXP工作组计算机无法访问的解决方法
  11. 再见Navicat! IDEA的这个兄弟真的很香!我粉了...
  12. PHP网站安装程序制作的原理、步骤、注意事项和示例代码
  13. 计算机odbc数据源管理位置,ODBC 常见数据源配置整理
  14. 经验分享:Windows聚焦图片位置在哪里,文件夹路径参上
  15. 面试时如何做好5分钟自我介绍?
  16. java如何做聚类分析_K-means算法的Java实现 聚类分析681个三国武将
  17. 网页在线 运行 html 代码
  18. 交易结果=市场理解×(交易策略+自我认识)
  19. SC92F8003读24C64程序
  20. 1分钟免费开通IDaaS云服务

热门文章

  1. Web应用程序信息收集工具wig
  2. UIPickerView隐藏透明条
  3. apollo mqtt linux qt,MQTT第5版更新,以及如何应用到Qt MQTT模块中
  4. 面试pythonweb开发的简历_【经验分享】对于Python各个方向的面试经验分享,非常给力!...
  5. 可由一个尾指针唯一确定的链表有_极客算法训练笔记(三),链表详细图解,别再逃避了朋友...
  6. ios相机黑边_黑边很碍眼很难看 苹果iPhone6黑边有什么用呢?
  7. c 判断文件是否存在_C语言编程之怎样判断某一文件是否存在
  8. eeglab中文教程系列(2)-绘制脑电头皮图
  9. seaborn系列 (18) | 线性回归图regplot()
  10. 九坤投资投身基础科研,携手IDEA成立联合实验室