[ /* 和 / 的区别 ] Difference between / and /* in servlet mapping url pattern
<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 FilterChain#doFilter().
<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 How to prevent static resources from being handled by front controller servlet which is mapped on /*. 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 How to handle static content in Spring MVC?
[ /* 和 / 的区别 ] Difference between / and /* in servlet mapping url pattern的更多相关文章
- Servlet获取URL地址
这里来说说用Servlet获取URL地址.在HttpServletRequest类里,有以下六个取URL的函数: getContextPath 取得项目名 getServletPath 取得Servl ...
- Invalid [xxx] in servlet mapping 、 <url-pattern>的匹配规则 、 DefaultServlet介绍
真的是很容易被忽视的错误,servlet 配置url的时候遇到问题,这个之前确实没有详细了解过. 出现这个错误的时候往往伴随着一系列高大上的错误,比如会出现类似[StandardEngine[Cata ...
- [冷知识] 连字符-减号-横杠的区别 difference between hyphen-minus-dash
因为早期打印机等宽的原因, 连字符和减号都是 -, 叫做hyphen-minus ,对应Unicode: U+002D(ASCII也是). 现在减号可以是:U+2212, 但编程语言中还是习惯使用U+ ...
- SVM中径向基函数与高斯核的区别 Difference between RBF and Gaussian kernel in SVM
Radial Basis Functions (RBFs) are set of functions which have same value at a fixed distance from a ...
- 应用程序池和应用程序域的区别(Difference between application pool and application domain)
来自StackOverFlow: http://stackoverflow.com/questions/8486335/difference-between-an-application-domai ...
- @WebServlet用注解来实现servlet和url的映射
package com.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Se ...
- 转:Servlet的url匹配以及url-pattern详解
Servlet是J2EE开发中常用的技术,使用方便,配置简单,老少皆宜.估计大多数朋友都是直接配置用,也没有关心过具体的细节,今天遇到一个问题,上网查了servlet的规范才发现,servlet中的u ...
- Servlet获取 URL 地址
使用 ServletRequest 的如下方法 getContextPath 取得项目名 getServletPath 取得Servlet名 getPathInfo 取得Servlet后的URL名,不 ...
- web.xml中servlet mapping标签
写了好多小项目后也没弄明白<url-pattern>的真正意义,写跳转的时候也是跳的三心二意的,今天查了一下web.xml的详细配置,看了看servlet-mapping的讲解,豁然开朗, ...
随机推荐
- android之自定义弹框
step1 创建窗体 final AlertDialog dialog =new Builder(this).create(); step2 获取View View viewDialog =View. ...
- ldap集成jenkins
jenkins版本:2.5.3,ldap插件:1.15 jenkins ldap支持需要安装ldap plugin,强烈建议插件安装版本为1.15及以上(支持ldap 配置测试) 安装插件: 系统管理 ...
- matlab的三维绘图和四维绘图
一.三维绘图1.曲线图plot3(X1,Y1,Z1,...):以默认线性属性绘制三维点集(X1,Y1,Z1)确定的曲线plot3(X1,Y1,Z1,LineSpec):以参数LineSpec确定的线性 ...
- markdownpad2-注册码-2017-02-23
MarkdownPad2.5/2 注册码 User: Soar360@live.com 授权: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImD ...
- bzoj 3262 陌上花开 - CDQ分治 - 树状数组
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- centos7.2 python2.7升级python3.6退格键不能用
yum install readline-devel ./configure --prefix=/usr/py/py3.6 (目录是自定义的这个根据实际情况来) make && ...
- Bootstrap3基础 form-horizontal 表单元素横向布局 简单示例
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- SpringBoot 超时设置
1.RestTemplate超时 设置配置HttpComponentsClientHttpRequestFactory中的RequestConfig属性 RestTemplateConfig: imp ...
- HIHOcoder 1466 后缀自动机六·重复旋律9
思路 后缀数组+博弈论的好题,首先对两个串都建出SAM,然后题目的要求实际上就是在SAM的trans上转移即可 DAG的博弈是经典问题,然后dfs求出SG函数,两个游戏的组合就是把SG函数异或起来,异 ...