Springboot is a resource that is interpreted as a stylesheet but wraps with text like MIME / htm

I see several answers to this question earlier, but none of the solutions that I tried worked.

My login.cssdoes not apply to login.htmlin my Spring boot application. I also use Thymeleaf.

Security is on - but I don’t think this is a problem, like in a browser. I do not see a download failure login.css- just a message:

The resource is interpreted as a stylesheet, but passed with text of the MIME / html type:

A further check in the browser indicates that it is requesting text/css, but receiving a response text/html.

html:

<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

<head>

<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatiable" content="IE-Edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="Login"/>


<title>LOGIN</title>

<!-- Latest compiled and minified CSS -->

....
<link rel="stylesheet" href="login.css" content-type="text/css"/>

Way to login.html

\src\main\resources\templates\login.html

Way to login.css

\src\main\resources\static\login.css

And just in case, it was a permissions problem:

.antMatchers("/css/**").permitAll()

, css, CDN. login.css 302.

+6
4

Spring Boot + Spring MVC. CSS, CDN, , CSS static/css HTML.

:

<!-- This first worked fine, loading all styles -->
<link th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"
      href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.7/css/bootstrap.min.css"
      rel="stylesheet" media="screen" />

<!-- This second one returned the content of an HTML - Content Type text/html -->
<link rel="stylesheet" th:href="@{/css/login/style.css}" href="/css/login/style.css" />

, Chrome Dev, , style.css, , HTML-.

, HTML , , @RequestMapping. @RequestMapping(name="...") @RequestMapping(path="...").

@RequestMapping(name = "/product/add", method = RequestMethod.GET)
public String add(Model model) {
    model.addAttribute("product", new Product());
    return "product/edit";
}

@RequestMapping(path = "/product/add", method = RequestMethod.GET)
public String add(Model model) {
    model.addAttribute("product", new Product());

    return "product/edit";
}

name path .

, .

, , .

+3

:

css :

/static/css/login.css 

..

html :

<link rel="stylesheet" href="/css/login.css" type="text/css"/>

. Out!

+1

For me, this was a definition more than a controller method that returns the same ModelAndView

@GetMapping("/home")
fun home(model: ModelMap): ModelAndView {
    model.addAttribute("model", SomeModel())
    return ModelAndView("home", model)
}

@GetMapping
fun index(model: ModelMap): ModelAndView {
    model.addAttribute("model", SomeModel())
    return ModelAndView("home", model)
}

Removing one of the methods solved the problem

0
source

if you are using mvc model. You can solve with

spring.mvc.servlet.load-on-startup=1

add application.properties file

I read from here

https://www.javatpoint.com/load-on-startup

0
source

Source: https://habr.com/ru/post/1674258/


All Articles