Spring mvc:访问外部文件夹的资源
我已将媒体(图片和电影)存储在文件夹中(例如 C:\test\tes.png),并且我尝试使用以下网址访问图片: http://localhost:8080/app/picture/test.png。 为此,我使用了资源标签(spring 3),如下所示:
<mvc:resources mapping="/picture/**" location="file:/test" />
当我尝试访问时,出现错误,没有更多详细信息。
未找到请求的资源
我在日志中:
2011-11-07 20:48:55,241 [http-8080-2] DEBUG org.springframework.web.servlet.DispatcherServlet - 名为“Family”的 DispatcherServlet 处理 [/Family/photos/testImage2.png 的 GET 请求] 2011-11-07 20:48:55,241 [http-8080-2] 调试 org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - 请求的匹配模式 [/photos/testImage2.png] 是 [/**] 2011-11-07 20:48:55,241 [http-8080-2] 调试 org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - 请求 [/photos/testImage2.png] 的 URI 模板变量为 {} 2011-11-07 20:48:55,242 [http-8080-2] 调试 org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - 使用处理程序 [org.springframework.web.SimpleUrlHandlerMapping] 将 [/photos/testImage2.png] 映射到 HandlerExecutionChain。 servlet.resource.DefaultServletHttpRequestHandler@3a779f5e] 和4 拦截机 2011-11-07 20:48:55,242 [http-8080-2] 调试 org.springframework.web.servlet.DispatcherServlet - [/Family/photos/testImage2.png] 的上次修改值为:-1 2011-11-07 20:48:55,242 [http-8080-2] 调试 org.springframework.web.servlet.DispatcherServlet - Null ModelAndView 返回到名称为“Family”的 DispatcherServlet:假设 HandlerAdapter 已完成请求处理 2011-11-07 20:48:55,242 [http-8080-2] 调试 org.springframework.web.servlet.DispatcherServlet - 成功完成请求
我当然不明白......
另一个问题:我不确定这是好的方法。访问外部文件夹上的媒体还有哪些其他解决方案?
提前致谢 !
I have stored medias (pictures and movies) in a folder (for example C:\test\tes.png) and I'm trying to access to pictures with an url like : http://localhost:8080/app/picture/test.png.
To do that, i have used resources tag (spring 3) as below :
<mvc:resources mapping="/picture/**" location="file:/test" />
When I try to access, I have an error with no more details.
Requested Resource Not Found
I have in logs :
2011-11-07 20:48:55,241 [http-8080-2] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Family' processing GET request for [/Family/photos/testImage2.png]
2011-11-07 20:48:55,241 [http-8080-2] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/photos/testImage2.png] are [/**]
2011-11-07 20:48:55,241 [http-8080-2] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/photos/testImage2.png] are {}
2011-11-07 20:48:55,242 [http-8080-2] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/photos/testImage2.png] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@3a779f5e] and 4 interceptors
2011-11-07 20:48:55,242 [http-8080-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/Family/photos/testImage2.png] is: -1
2011-11-07 20:48:55,242 [http-8080-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'Family': assuming HandlerAdapter completed request handling
2011-11-07 20:48:55,242 [http-8080-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
I have certainly not all understand...
Another question : I'm not sure this is the good approach. What are others solutions to access to media on external folder ?
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个问题:“映射”
我不是 100% 确定,但我猜想,该位置缺少最后一个
/
。将其更改为:
另一个问题:我不确定这是一个好方法。访问外部文件夹上的媒体还有哪些其他解决方案?
以我的拙见,向网站用户授予对文件夹的完全读取权限是非常糟糕的做法。注意,访问不仅限于文件夹,用户还可以访问所有子文件夹。
*即使您决定忽略此警告,您也必须测试如果某些使用调用从 Spring 3.2.12、4.0.8、4.1.2 开始,资源处理程序确保您不访问指定资源文件夹之外的文件夹。 (SPR-12354:使用静态资源处理进行目录遍历 (CVE-2014-3625))http://localhost:8080/app/picture/../someFile
会发生什么情况。**我不知道会发生什么,但是 **120% 确保没有人可以访问picture
文件夹之外的任何文件! -- 我查看了 spring 的实现,发现 spring 已经处理了这个问题。*First question: "the mapping"
I am not 100% sure, but I would guess, there is a final
/
missing for the location.change it to:
Another question : I'm not sure this is the good approach. What are others solutions to access to media on external folder ?
In my humble opinion, it is very bad practice to give an web site user full read access to an folder. Attention the access is not only limited to the folder, but the user can also access all sub folders.
*And even if you decided to ignore this warning, then you must test what happen if some use invokeSince Spring 3.2.12, 4.0.8, 4.1.2 the Resource Handler make sure that you an not access an folder outside the specified resource folder. (SPR-12354: Directory traversal with static resource handling (CVE-2014-3625))http://localhost:8080/app/picture/../someFile
.** I don't know what would happen, but **make 120% sure that nobody can access any file outside thepicture
Folder! -- I have had a look into the spring implementation, and it seams that spring already handle this issue.*如果您的
.js/.css/.img
文件存储在驱动器d:\\ext_resources
中,则添加
弹簧配置文件。 例如mvc-dispatcher-servlet.xml.xml
文件...这意味着
/ext
将指示文件夹d:\\ext_resources
,其中包含.html/.jsp/.ftl/.jsf
文件。您也可以在
ext_resources
文件夹中拥有子文件夹,例如image
文件夹。然后使用 URL 中的子文件夹。
If your
.js/.css/.img
files are stored in drived:\\ext_resources
then add<mvc:resources>
in spring configaration file. e.g.mvc-dispatcher-servlet.xml.xml
file...This means
/ext
will indicate folderd:\\ext_resources
, which contains.html/.jsp/.ftl/.jsf
files.you can have sub-folder too in
ext_resources
folder likeimage
folder.Then use subfolder in URL.