[ /* 和 / 的区别 ] Difference between / and /* in servlet mapping url pattern
时间:2022-03-12 16:36
<url-pattern>/*</url-pattern>
The /*
on a servlet overrides all other servlets,
including all servlets provided by the servletcontainer such as the default servlet and the JSP servlet.
无论你发送什么请求,都会经过这个servlet.
通常来讲,只会用在Filter上,进行全部过滤.
It is able to let the request continue to any of the servlets listening on a more specific URL pattern by calling .
<url-pattern>/</url-pattern>
The /
doesn‘t override any other servlet.
它只替换servlet容器的内置默认servlet.
ps:默认servlet是为那些不匹配任何注册过的servlet准备的.
通常,它只会在静态资源上调用(CSS/JS/image/etc)和直接侦听.
servlet容器的内置servlet也有处理Http缓存请求,媒体流和文件下载的能力.
通常,你不会想要override默认的服务器.
不然你就不得不取代它的任务,这可不轻松.
因此,这对于servlet是一个不好的URL-pattern.
至于JSP页面为什么不会hit到这个servlet,是因为servlet容器的内置JSP servlet会被调用.
--已经被默认映射成更详细的RUL pattern *.jsp
<url-pattern></url-pattern>
然后,还有一个空字符串URL pattern.
当context root被请求时,它就会被调用.
这和<welcome-file>途径是不同的,
它的子文件夹被请求时,它不会被调用.
这更像是你需要一个"主页servlet"时想要寻找的URL pattern.
空字符和/ URL pattern的定义和直观期待有所差距,很容易混淆.
Front Controller
In case you actually intend to have a front controller servlet, then you‘d best map it on a more specific URL pattern like *.html
, *.do
, /pages/*
, /app/*
, etc. You can hide away the front controller URL pattern and cover static resources on a common URL pattern like /resources/*
, /static/*
, etc with help of a servlet filter. See also . Noted should be that Spring MVC has a builtin static resource servlet, so that‘s why you could map its front controller on /
if you configure a common URL pattern for static resources in Spring. See also
相关推荐
- Android系统编程入门系列之界面Activity交互响应
- 新型横向移动工具原理分析、代码分析、优缺点以及检测方案
- uni-app滚动视图容器(scroll-view)之监听上拉事件
- uniapp h5,app两端复制文本
- Android系统编程入门系列之界面Activity响应丝滑的传统动画
- 【Azure 应用服务】App Service 配置 Application Settings 访问Storage Account得到 could not be resolved: '*.file.core.windows.net'的报错。没有解析成对应中国区 Storage Account地址 *.file.core.chinacloudapi.cn
- 诺基亚短信生成!太好玩了
- iOS 跳转App Store进行评分
- 开发一个即时通讯App
- 关闭苹果IOS app自动更新
电脑软件
本类排行
- 1关闭苹果IOS app自动更新
- 2iOS 跳转App Store进行评分
- 3诺基亚短信生成!太好玩了
- 4Android系统编程入门系列之界面Activity响应丝滑的传统动画
- 5uniapp h5,app两端复制文本
- 6uni-app滚动视图容器(scroll-view)之监听上拉事件
- 7新型横向移动工具原理分析、代码分析、优缺点以及检测方案
- 8Android系统编程入门系列之界面Activity交互响应
- 9开发一个即时通讯App
- 10【Azure 应用服务】App Service 配置 Application Settings 访问Storage Account得到 could not be resolved: '*.file.core.windows.net'的报错。没有解析成对应中国区 Storage Account地址 *.file.core.chinacloudapi.cn