加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 是否可以为Jetty的servlet映射使用正则表达式?

发布时间:2020-12-15 00:51:50 所属栏目:Java 来源:网络整理
导读:我有这个映射 servlet-mappingservlet-nameservice/servlet-nameurl-pattern/service/*/url-pattern/servlet-mapping 但我也想要 /服务/主 映射到主servlet. servlet-mappingservlet-namemaster/servlet-nameurl-pattern/service/master/url-pattern/servlet
我有这个映射
<servlet-mapping>
<servlet-name>service</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>

但我也想要
/服务/主
映射到主servlet.

<servlet-mapping>
<servlet-name>master</servlet-name>
<url-pattern>/service/master</url-pattern>
</servlet-mapping>

我相信这里存在冲突,因为调用/ service / *会立即触发服务servlet.有没有办法让我在servlet映射中使用某种排除,或者可以使用regexp来做我想做的事情?

解决方法

Servlet映射始终??使用最具体的匹配,因此路径< context> / service / master将始终映射到master.

这是Servlet 3.0 spec的第一个映射规则:

  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. Many containers provide an implicit default servlet for serving content.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读