H
H
himmelcross2021-06-11 08:23:22
Spring
himmelcross, 2021-06-11 08:23:22

Why does the .html page stop seeing style.css?

In a spring application, the .html start page handles the tag

<link href="css/style.css" type="text/css"  rel="stylesheet"/>.
But after performing the operations:
1. following the link <a th:href="@{/anylink})}"</a>
2. controller code and return "redirect:" + url;
3. the redirect page does not see the tag <link href="..."/>
This has the consequence that for bootstrap you have to write cdn links, not local ones
<link rel="stylesheet" href="css/bootstrap.min.css"/>
and other inconveniences.
Replacing redirect with forward didn't work. The System.getProperties() variables are the same on all .html pages. Tried in browsers firefox and opera, the effect is consistently present.
Somewhere there is a change of environment variables, but I can't figure out where.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2021-06-11
@sergey-gornostaev

It's early for you in Spring, very early. You do not distinguish relative links from absolute ones, and these are the basics known to any layout designer.

O
Orkhan Hasanli, 2021-06-11
@azerphoenix

I recommend reading the thymeleaf documentation.
Make sure the css file is in resources/static/css/style.css
You are connecting the styles incorrectly.

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

It should be like this:
<link th:href="@{/css/style.css}" type="text/css"  rel="stylesheet"/>.

With this syntax, the context path is taken into account.
Well, as noted by a colleague Sergey Gornostaev , learn the basics of HTML / CSS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question