我试图在jsp中包含来自资源的引导文件,但是由于某些原因,它不起作用(样式未应用于HTML元素)。我的视图标题如下:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<!-- authentication.jsp -->
<!-- this works
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous"> -->
<!--this doesn't work-->
<link href="<c:url value="/webapp/resources/styles/bootstrap.min.css"/>" rel="stylesheet" media="screen"/>
<title>Title</title>
</head>
<body>
<!--................-->
</body>
</html>
这是我的文件夹结构:
这是我的AppConfig类:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.gtu.gtesting"})
public class AppConfig extends WebMvcConfigurationSupport {
@Bean
public InternalResourceViewResolver viewResolver(){
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}
答案 0 :(得分:0)
您已经为此声明了resourceHandler
。因此,就像在.jsp
<link href="resources/styles/bootstrap.min.css" rel="stylesheet"/>
这应该可以。如果不适合您,请尝试
<link href="<c:url value='resources/styles/bootstrap.min.css' />" rel="stylesheet" />
或所有完整路径
<link href="${pageContext.request.contextPath}/resources/styles/bootstrap.min.css" rel="stylesheet" />