Spring mvc 如何访问images文件夹中的子文件夹(获取404)?
我在“图像”文件夹中添加了一个新的子文件夹,无法解析新图像 未能加载资源:。。。404(未找到)Spring mvc 如何访问images文件夹中的子文件夹(获取404)?,spring-mvc,Spring Mvc,我在“图像”文件夹中添加了一个新的子文件夹,无法解析新图像 未能加载资源:。。。404(未找到) http://localhost:8080/mywebapp/content/images/subdir/mysubdirimage.png 我的目录结构: src -- main --java --webapp --content --images // <- these resolve --subdir // <- n
http://localhost:8080/mywebapp/content/images/subdir/mysubdirimage.png
我的目录结构:
src
-- main
--java
--webapp
--content
--images // <- these resolve
--subdir // <- new subdir...resolve fail for images
src
--主要
--爪哇
--网络应用
--内容
--images/添加的mvc dispatcher servlet行已经完成了一半,但需要将其更改为:
<mvc:resources mapping="/images/**" location="/content/images/" />
}
最后,在上面的示例中,尝试URL(如上所述):
您还应该能够通过控制器中定义的@RequestMapping模式访问图像。例如,使用我上面给出的示例,您可以输入URL:
http://localhost:8080/mywebapp/staticImages
文件夹和图像的权限是什么?@CurtisMattoon:“subdir”是只读的,“images”dir是只读的。如果我把图片放在“图片”目录中,它们会正确解析。非常感谢!非常非常有帮助!
<mvc:resources mapping="/images/**" location="/content/images/" />
@RequestMapping(value = "/staticImages", method = RequestMethod.GET)
public String showImage() {
return "/images/subdir/mysubdirimage.png";
http://localhost:8080/mywebapp/images/subdir/mysubdirimage.jpg
http://localhost:8080/mywebapp/staticImages