0

@English isn't my first language.

I use freemaker in my spring project. But I can't link css file.

Here tree and code

Error : GET http://localhost:8080/static/style.css net::ERR_ABORTED 404 login:6

<link rel="stylesheet" href="/static/style.css"/> isn't wrong..

Error

<#macro page>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Getting Started: Serving Web Content</title>
    <link rel="stylesheet" href="/static/style.css"/>
<#--<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">-->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

</head>
<body>
<#nested>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
</#macro>
clevercat
  • 43
  • 1
  • 9
  • 2
    your first error is to link to code and an error message, instead of pasting those in your question. – Stultuske Mar 21 '19 at 10:40
  • @clevercat Please, copy or type the code and error text into the question - [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – ilinykhma Mar 21 '19 at 10:42
  • Watch image 1 at line 6. (what we could see at image 2). Where is the problem? Code fine. – clevercat Mar 21 '19 at 10:44
  • The template is valid, check under what resource your CSS is accessible, then fix the url in your template. – Beri Mar 21 '19 at 11:54
  • check this link:https://stackoverflow.com/questions/27170772/where-to-put-static-files-such-as-css-in-a-spring-boot-project#answer-27173104 – soorapadman Mar 22 '19 at 12:33

1 Answers1

0

How have you configured the /src/main/resources/static directory to serve the files?

If you using Spring Boot and its default configuration, then static isn't part of the URL path, so you should be using

<link rel="stylesheet" href="/style.css"/>
RoToRa
  • 37,635
  • 12
  • 69
  • 105
  • I didn't change any configurations. Search what's wrong soooooo long.. How I could change this configurations? – clevercat Mar 23 '19 at 21:15
  • Omfg just didn't change any think and now it works.. Set path like you write. Thank you and soorapadman for help! – clevercat Mar 23 '19 at 21:37