[英]Unable to serve css files placed in src/main/resources/static/css/ folder to client in Spring boot application
I know this has been posted too many times but I'm still facing this issue. 我知道这已发布太多次但我仍然面临这个问题。 css files placed in static/css folders are not being served to client during get requests. 放置在static / css文件夹中的css文件在获取请求期间未提供给客户端。
I'm getting net::ERR_ABORTED 404 on client side with only jsp content being rendered. 我在客户端获得了net :: ERR_ABORTED 404,只渲染了jsp内容。
I'm using Spring boot 2.1.4 and Netbeans 9.0 我正在使用Spring boot 2.1.4和Netbeans 9.0
Here is the project structure: 这是项目结构:
jsp code: jsp代码:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Admin Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/styles.css">
</head>
Please help. 请帮忙。
You should use an absolute path. 你应该使用绝对路径。 Change 更改
<link rel="stylesheet" href="css/styles.css">
to 至
<link rel="stylesheet" href="/css/styles.css">
I found the issue. 我发现了这个问题。 The problem is I have changed the context-path for the application and the browser is unable to resolve the path for static content. 问题是我更改了应用程序的上下文路径,浏览器无法解析静态内容的路径。
I had to prefix the href with "/{context-path}/css/styles.css" instead of "css/styles.css". 我不得不在href前加上“/{context-path}/css/styles.css”而不是“css / styles.css”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.