SME*_*SME 7 java spring spring-mvc spring-boot
有很多关于spring boot没有加载静态资源并且已经全部读过的问题(几乎)我仍然无法解决这个问题.在这个阶段,我选择不使用弹簧靴,但我仍然想知道问题是什么.我正在使用Eclipse,Java 8和Maven.
我有一个如下所示的应用程序类:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个css文件 - src/main/resources/static/style.css
并从jsp中引用它:
<link href="<c:url value='style.css'/>" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
页面加载但不加载css.这是错误 - 405方法不允许
我认为思考是正确的但不确定.所有帮助赞赏.
基于下面的一些评论,这就是现在的情况.
我的jsp文件在src/main/resources/application.properties中配置如下:
spring.mvc.view.prefix:/WEB-INF/views/
spring.mvc.view.suffix:.jsp
Run Code Online (Sandbox Code Playgroud)
我的Jsp非常简单,位于/WEB-INF/views/home.jsp
<!DOCTYPE html>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<link href="public/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<p>Hello world!</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我也试过像这样链接我的css文件:
<link href="style.css" rel="stylesheet" type="text/css"/>
Run Code Online (Sandbox Code Playgroud)
我的css文件位于webapp/public/style.css中,也非常简单
p {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
我的jsp加载但不是css.我使用各种方法运行我的应用程序,包括:
从命令行 - java -jar contacts.jar
在eclipse中 - mvn spring-boot:run和mvn tomcat7:run-war也可以在Eclipse中通过右键单击Application.class文件并选择Run As - > Java Application.
我正在使用Spring Boot版本1.4.0.RELEASE
假设您没有禁用WebMvcAutoConfiguration
在目录public上创建文件夹webapp
JSP在你的页面上
<link href="public/style.css" rel="stylesheet" type="text/css"/>
Run Code Online (Sandbox Code Playgroud)
假设你的style.css位于public文件夹中
webapp > public > styles.css
| 归档时间: |
|
| 查看次数: |
13172 次 |
| 最近记录: |