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