0
我对Java EE Spring Framework比较新。 我运行Netbeans中的一个Spring MVC的春天Maven项目和我对“网页”目录中的项目文件的结构如下:Java spring mvc资源处理程序路径
织网的页面
--Web-INF
---意见
----的welcome.jsp
-resources
--DPI.PNG
,这是配置类:
公共类您好WorldConfiguration {
@Bean(name = "HelloWorld")
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Css resource.
registry.addResourceHandler("/resources/**") //
.addResourceLocations("/resources/");
}
}
,并在我的welcome.jsp使用下面的HTML访问图像:
<img src='/resources/DPI.PNG'>
,当我访问网页它给404未找到图像,
是什么问题?
请注意'/ resources/DPI.PNG'会指向'localhost/resources/DPI.PNG'。除非你做了一些不同的设置,你的应用程序将有一个上下文路径。如果要显示图像,则需要考虑上下文路径。 [这里](https://stackoverflow.com/questions/5066061/context-path-in-uris-of-static-resources-do-i-really-need-to-specify-it)你可以找到一个例子JSTL。 – BackSlash
要进行调试,您还可以尝试在Chrome控制台中监控网络选项卡,并查看为该URL调用了哪个URL。 – SaAn