[ /* 和 / 的区别 ] 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的讲解,豁然开朗, ...
随机推荐
- bzoj 2115 Xor - 线性基 - 贪心
题目传送门 这是个通往vjudge的虫洞 这是个通往bzoj的虫洞 题目大意 问点$1$到点$n$的最大异或路径. 因为重复走一条边后,它的贡献会被消去.所以这条路径中有贡献的边可以看成是一条$1$到 ...
- shell if 语句
一.过程式 编程语言的代码执行顺序: a.顺序执行:逐条执行: b.选择执行: 代码有一个分支:条件满足时才会执行: 俩个或以上的分支:只会执行其中一个满足条件的分支: c.循环执行: 代码片段(循环 ...
- Python3 tkinter基础 Canvas create_rectangle 画虚边的矩形 create_oval 画椭圆形 圆形
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- eMMC ext4综述【转】
本文转载自:https://blog.csdn.net/lieye_leaves/article/details/78214410 eMMC ext4综述一.系统的引导启动1.1系统的引导启动http ...
- FJNU2018低程F jq解救fuls (贪心乱搞)题解
题目描述 一天fuls被邪恶的"咕咕咕"抓走了,jq为了救fuls可谓是赴汤蹈火,费了九牛二虎之力才找到了"咕咕咕"关押fuls的地方. fuls被关在一个机关 ...
- How to search for ? (question mark) in Excel
The ? is a wildcard which represents a single character, and the * is a wildcard character that repr ...
- C#获取文件MD5值方法
https://www.cnblogs.com/Ruiky/archive/2012/04/16/2451663.html private static string GetMD5HashFromFi ...
- [HDU 1215] 七夕节(求因子,不超时)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1215 //注意怎么处理不超时 #include<iostream> #include< ...
- Bytom移动端钱包SDK开发基础
比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom Byto ...
- ETCD原理
etcd:从应用场景到实现原理的全方位解读 从etcd的架构开始,深入到源码中解析etcd 1 架构 从etcd的架构图中我们可以看到,etcd主要分为四个部分. HTTP Server: 用于处理用 ...