春季:/**和/*关于路径的差异 [英] Spring: Difference of /** and /* with regards to paths
问题描述
当我们引用路径时,两个星号而不是一个星号有什么区别?
What's the difference between two asterisks instead of one asterisk when we refer to paths?
之前,我正在调试Spring 3项目.我试图使用添加一个.swf
Earlier I was debugging my Spring 3 project. I was trying to add a .swf using
<spring:url var="flashy" value="/resources/images/flash.swf"/>
我的web.xml的ResourceServlet看起来像
With my web.xml's ResourceServlet looking like
<servlet-name>Resource Servlet </servlet-name>
<url-pattern>/resources/*</url-pattern>
但是不幸的是我遇到了这个错误:
But unfortunately I was getting this error:
WARN org.springframework.js.resources.ResourceServlet - An attempt to access a protected resource at /images/flash.swf was disallowed.
我发现这很奇怪,因为访问了images
文件夹中的所有图像,但是.swf为何受到保护"?
I found it really strange since all my images in the images
folder were accessed but how come my .swf was "protected"?
然后,我决定将/resources/*
更改为/resources/**
并最终成功.我的问题是...为什么?
Afterwards, I decided to change the /resources/*
to /resources/**
and it finally worked. My question is... why?
推荐答案
这是Apache ant
中使用的路径模式,spring团队将其实现并在整个框架中使用它.
This is a path pattern that used in Apache ant
, spring team implement it and use it throughout the framework.
有关参考,请参见 AntPathMatcher a>(最新的 javadoc似乎有问题,所以我链接了一个旧的.)
For reference, see javadoc of AntPathMatcher (newest javadoc seems to have problem, so I link an old one).
根据文档,回到您的问题,它只有3条规则:
Back to your problem, according to the document, it only have 3 rules:
-
?
匹配一个字符 -
*
匹配零个或多个字符 -
**
匹配路径中的零个或多个目录"
?
matches one character*
matches zero or more characters**
matches zero or more 'directories' in a path
这篇关于春季:/**和/*关于路径的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!