现在的位置: 首页 > 综合 > 正文

Web.xml中的url-pattern详解

2018年05月11日 ⁄ 综合 ⁄ 共 854字 ⁄ 字号 评论关闭

开发好几年了,记录的东西也不少,但是都没有认真记录归纳过,今天比较闲,就抽时间把以前的点滴整理出来。同时分享一下自己学习与工作中的困惑与收获,希望能够帮助后来者少走点弯路。

刚开始做jee开发,配置web.xml的时候总不会配置url-pattern的规则,后来经过自己实践也得到一些经验。

首先说下,其实url-pattern就是说的url模式,就是容器在查找时根据这个模式来找到具体的servlet来执行。

先来看一段规范中的

In the Web application deployment descriptor, the following syntax is used to define mappings:

  • 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. 
  • All other strings are used for exact matches only.--这一句不是规范

翻译下来就是:

在web.xml文件中,以下语法用于定义映射:

以”/’开头和以”/*”结尾的是用来做路径映射的。

以前缀”*.”开头的是用来做扩展映射的。如*.action

 “/” 是用来定义default servlet映射的。

其它所的有就是用来精确匹配的。

但是有时我们也能够遇到/app/**的,这种情况下一般是Ant的表示语法,也是精确匹配(见标注)

这个可以参考:

http://stackoverflow.com/questions/13843294/what-does-the-double-wildcard-on-a-servlet-mapping-url-pattern-mean

【上篇】
【下篇】

抱歉!评论已关闭.