Web.xml中的url-pattern详解

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

刚开始做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


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值