[ /* 和 / 的区别 ] 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的讲解,豁然开朗, ...
随机推荐
- python简说(二十一)开发接口
一.flask举例 import flaskserver = flask.Flask(__name__)#新建一个服务,把当前这个python文件当做一个服务@server.route('/login ...
- ORA-16038 ORA-19809 ORA-00312
问题表现: 连接数据库启动报错,ORA-03113, 查看详细的alert日志发现更多报错,如下 ORA-19809: 超出了恢复文件数的限制ORA-19804: 无法回收 209715200 字节磁 ...
- mysqldump: Couldn't execute 'SHOW VARIABLES LIKE 'ndbinfo_version'': Native table 'performance_schema'.'session_variables' has the wrong structure (1682)
centos7.5 导出整个数据库报错 问题: [root@db01 ~]# mysqldump -uroot -pBgx123.com --all-databases --single-transa ...
- 一些常用的mysql语句实例-以后照写
create database blog; create table blog_user ( user_Name char(15) not null check(user_Name !=''), us ...
- windows下使用LibreOffice的体验
我在家里一般是使用Ubuntu,学校这个网络需要e信拨号,还是只能用Windows主用,以前我在Ubuntu一直使用的是LibreOffice,这次看见学校电脑很乱了就重装了系统,MSOffice真的 ...
- P3244 [HNOI2015]落忆枫音
思路 给出了一个DAG,要求以1为根的外向树的个数 如果没有加边的条件,就非常好做 每个点都只保留一条入边,最后得到的一定就是一个符合条件的树了(因为给了一个DAG啊) 所以答案是\(\prod_{i ...
- Netty Reactor 线程模型笔记
引用: https://www.cnblogs.com/TomSnail/p/6158249.html https://www.cnblogs.com/heavenhome/articles/6554 ...
- js中获取当前浏览器类型
本文为博主原创,转载请注明出处: 在应用POI进行导出时,先应用POI进行数据封装,将数据封装到Excel中,然后在进行download下载操作,从而完成 POI导出操作.由于在download操作时 ...
- PTA 输出全排列(20 分)
7-2 输出全排列(20 分) 请编写程序输出前n个正整数的全排列(n<10),并通过9个测试用例(即n从1到9)观察n逐步增大时程序的运行时间. 输入格式: 输入给出正整数n(<10). ...
- C语言: 从 CodeBlocks 到 Microsoft Visual Studio 2017
开学到现在寒假,学习了一个学期的C语言,同时也已然用了大半年的 CodeBlocks 来写 C/C++ 程序.CodeBlocks 是写 C/C++ 语言的程序最轻量的IDE(集成开发环境),在 C ...