简体   繁体   English

无法在Spring引导应用程序中将src / main / resources / static / css /文件夹中的css文件提供给客户端

[英]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.

相关问题 无法通过Spring Boot提供静态资源 - Unable to serve static resources with Spring Boot spring 启动 - 我可以读取按环境放置在 src/main/resources 中的 json 文件吗 - spring boot - Can I read json files placed in src/main/resources by environment Spring开机测试:@Sql注解无法定位src/test/resources中放置的sql文件 - Spring boot test: @Sql annotation Unable to locate sql files placed in src/test/resources 如何在 Spring Boot 中访问 src/main/resources/ 文件夹中的资源文件 - How to access a resource file in src/main/resources/ folder in Spring Boot Spring Boot不提供src / main / resources / public目录中的某些图像 - Spring boot doesn't serve some of the images from the src/main/resources/public directory Spring Boot无法在/ resources / static / images文件夹中找到图像 - Spring Boot unable to find the images in /resources/static/images folder 我将前端文件放在哪个文件夹中 Spring 引导。 是 Src/main/resource 还是 Src/main - Which Folder do i put my frontend files in Spring boot. Is it Src/main/resource or Src/main 无法在Spring Boot应用程序中访问和使用静态资源 - Unable to access and use static resources in Spring Boot Application 使用 Spring Boot 和 React Router 提供静态文件夹 - Serve static folder with Spring Boot and React Router Liquibase 未从 Spring Boot 中的现有数据库在 src/main/resources 文件夹中生成 changeLog 文件 - Liquibase not generating changeLog file in src/main/resources folder from existing DB in Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM