Spring: Difference of /** and /* with regards to paths

谁都会走 提交于 2019-11-26 18:44:41

问题


What's the difference between two asterisks instead of one asterisk when we refer to paths?

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"/>

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.

I found it really strange since all my images in the images folder were accessed but how come my .swf was "protected"?

Afterwards, I decided to change the /resources/* to /resources/** and it finally worked. My question is... why?


回答1:


This is a path pattern that used in Apache ant, spring team implement it and use it throughout the framework.

For reference, see javadoc of AntPathMatcher (newest javadoc seems to have problem, so I link an old one).

Back to your problem, according to the document, it only have 3 rules:

  1. ? matches one character
  2. * matches zero or more characters
  3. ** matches zero or more 'directories' in a path


来源:https://stackoverflow.com/questions/12569308/spring-difference-of-and-with-regards-to-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!