Catch-all(通配符)servlet url-pattern覆盖文件扩展名模式

Ret*_*ner 9 web.xml servlets zk url-pattern

我想实现以下目标:

/webapp-context/Page-1               -> Handled by my custom "ContentServlet"
/webapp-context/Another-Page         -> Handled by my custom "ContentServlet"
/webapp-context/Page-with-long-title -> Handled by my custom "ContentServlet"

/webapp-context/_cms/<something>.zul -> Handled by ZK framework
Run Code Online (Sandbox Code Playgroud)

我的最新尝试看起来像这样(web.xml提取):

  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zul</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>myContentServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

不幸的是现在我的内容servlet处理所有请求(我认为更具体的模式优先?).

如果我将我的内容servlet映射到模式"/ webapp-context/content/*",则不存在冲突,但这不是我想要的.

谢谢你的时间.

Ret*_*ner 11

我刚刚通过这个问题找到了一个解决方案:servlet映射url模式中的/和/*之间的区别

使用'/'而不是'/*'为我做了诀窍.

<servlet-mapping>
  <servlet-name>myContentServlet</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)