我想在我的Spring MVC Project的JSP頁面中顯示圖像,但圖像不起作用。Spring MVC顯示圖像
的圖像放在src /主/ web應用/資源/ images文件夾
請找到下面的代碼。任何幫助將不勝感激:
@Configuration
@EnableWebMvc
public class WebMVCConfig extends WebMvcConfigurationSupport {
// Resource reading from jsp
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//Here I declare a mapping of src\main\webapp\resources folder and all its content to a resource location value /resources/
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/");
}
// Property reading from jsp
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("/WEB-INF/i18n/application");
return messageSource;
}
// View Resolver
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
//internalResourceViewResolver.setViewClass(JstlView.class);
internalResourceViewResolver.setPrefix("/");
internalResourceViewResolver.setSuffix(".jsp");
return internalResourceViewResolver;
}
}
在JSP中它被稱爲:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
<img src="<c:url value='/resources/images/abc.jpg' />" >
</body>
</html>
我已經編輯你的建議,但仍然沒有運氣@覆蓋 \t公共無效addResourceHandlers(ResourceHandlerRegistry註冊表){ \t \t registry.addResourceHandler( 「/資源/ **」)。addResourceLocations( 「/資源/」) ; \t \t \t} – astar
一次清潔,建立自己的源代碼 –
完成,但沒有運氣還是 – astar