[ /* 和 / 的区别 ] 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的讲解,豁然开朗, ...
随机推荐
- rpm command
rpm 实现程序管理 安装:-ivh ,--nodeps ,--replacepkgs 卸载: -e, --nodeps 升级: -Uvh -Fvh , --nodeps, --oldpackag ...
- 如何使用AsyncTask
1 如何使用handler,安卓规定只能再UI线程里面刷新UI,但是不能再UI线程里面执行耗时操作.所以我们要把耗时操作放在子线程里,然后把要刷新UI的操作传递到handler里面,然后在由Handl ...
- 【MonkeyRunner环境搭建】
一.配置MonkeyRunner环境变量 1.首先下载一个AndroidSDK,在SDK的目录中的tools文件夹中,直接带有MonkeyRunner 2.打开MonkeyRunner的方式: |-- ...
- Shell脚本,更改Info.plist中的日期等
#!/bin/bashroot_src=$(dirname $(PWD)) bundle_name='RandomDebbot.bundle' target_path=$root_src/ecovac ...
- 02MySQL中的数据类型
一.数值 INT DECIMAL 准确的小数值 FLOAT DOUBLE 二.字符串类型 CHAR(m) 此数据类型用于表示固定长度的字符串,可以包含最多达255个字符,其中m代表字符串的长度.长度固 ...
- Python3基础 list + *运算 扩充列表
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- P4137 Rmq Problem / mex
目录 链接 思路 线段树 莫队 链接 https://www.luogu.org/problemnew/show/P4137 思路 做了好几次,每次都得想一会,再记录一下 可持久化权值线段树 区间出现 ...
- oracle单行函数 之 数字函数
Round(数字 \ 列 [,保留小数的位数]):四舍五入 select Round(1234.45,1) from dual = 1234.5 Trunc(数字 \ 列 [,保留小数的位数] ...
- C# 控件线程匿名委托定义
当你在子线程中要修改主线程某个控件的值时,有不想再去定义一个线程变量时,就可以直接使用线程匿名委托来实现. 主要是方便快捷 控件.BeginInvoke(new ThreadStart(delegat ...
- ZJOI 2015 幻想乡战略游戏(动态点分治)
题意 https://loj.ac/problem/2135 思路 首先要明确一点,答案分布是有单调性的.什么意思呢?假设我们的答案在 \(u\) 节点,\((u,v)\) 之间有一条边且 \(u\) ...