我有一个带有 Java 配置但没有 ThymeLeaf 的引导应用程序,并且在我的 JSP 页面中引用 CSS 时遇到了问题。当我启动应用程序时,我在浏览器控制台中看到了这个。
localhost/:1 Refused to apply style from 'http://localhost:8080/SheridanSports/css/nav.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
这是项目的结构
索引.jsp
<head>
<title>Spring Sports-Home</title>
<base href="/">
<link href="${pageContext.request.contextPath}/css/nav.css" rel="stylesheet" type="text/css">
</head>
AppConfig.java
@Configuration
@EnableWebMvc
//@ComponentScan(basePackages = "com.abc.SheridanSportsWAR")
public class AppConfig implements WebMvcConfigurer{
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
return bean;
}
}
