我已将媒体(图片和电影)存储在文件夹中(例如 C:\test\tes.png),并且我正在尝试访问具有如下 URL 的图片: http://localhost:8080/app/picture/test.png 。 为此,我使用了资源标签(spring 3),如下所示:
<mvc:resources mapping="/picture/**" location="file:/test" />
当我尝试访问时,出现错误,但没有更多详细信息。
Requested Resource Not Found
我有日志:
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
我当然没有全部理解...
另一个问题:我不确定这是个好方法。访问外部文件夹上的媒体还有哪些其他解决方案?
提前致谢!
最佳答案
第一个问题:“映射”
我不是 100% 确定,但我猜想,该位置缺少最后一个 /
。
将其更改为:
<mvc:resources mapping="/picture/**" location="file:/test/" />
另一个问题:我不确定这是个好方法。访问外部文件夹上的媒体还有哪些其他解决方案?
以我的愚见,向网站用户授予对文件夹的完全读取权限是非常糟糕的做法。注意,访问不仅限于文件夹,用户还可以访问所有子文件夹。
*即使您决定忽略此警告,您也必须测试如果某些使用调用 从 Spring 3.2.12、4.0.8、4.1.2 开始,资源处理程序确保您不访问指定资源文件夹之外的文件夹。 (SPR-12354: Directory traversal with static resource handling (CVE-2014-3625))http://localhost:8080/app/picture/../someFile
会发生什么情况.** 我不知道会发生什么,但是 **120% 确保没有人可以访问 picture
文件夹之外的任何文件! -- 我查看了 spring 的实现,发现 spring 已经处理了这个问题。*
关于 Spring MVC :resources access to outside folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8041839/