熟悉的代码:
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
我的理解是/*
映射到http://host:port/context/*
。
/
又是怎样的呢?它肯定不仅映射到http://host:port/context
根目录。实际上,它将接受http://host:port/context/hello
,但将拒绝http://host:port/context/hello.jsp
。
有人能够解释一下http://host:port/context/hello
是如何映射的吗?
/**
模式表示什么吗? - Sajib Acharya/**
后缀模式可以从第三方库/框架(如Spring和Shiro)中识别。请查阅其文档以获取详细信息。 - BalusC/*
并不会覆盖所有其他的servlet,也不是所有的请求都会到达那里。容器首先会尝试找到一个精确匹配,然后是最长路径前缀匹配。因此,具有映射/foo/bar
或具有映射/foo/*
的servlet将在具有映射/*
的servlet之前触发。但是,具有/*
的servlet将覆盖任何扩展映射,如*.html
。 - Robert Tupelo-Schneck