Spring:/** 和/* 在路径方面的差异 [英] Spring: Difference of /** and /* with regards to paths

查看:38
本文介绍了Spring:/** 和/* 在路径方面的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们提到路径时,两个星号而不是一个星号有什么区别?

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 - 不允许尝试访问/images/flash.swf 中的受保护资源.

我觉得很奇怪,因为我在 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 (最新 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:

  1. ? 匹配一个字符
  2. * 匹配零个或多个字符
  3. ** 匹配路径中的零个或多个目录"
  1. ? matches one character
  2. * matches zero or more characters
  3. ** matches zero or more 'directories' in a path

这篇关于Spring:/** 和/* 在路径方面的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆