css and js url not working on base file thymeleaf by layout decorate
up vote
0
down vote
favorite
i have a base.html where i have put on my all css and js file and it's working fine when i define url without "/".
Here is my code
my controller
@GetMapping("/department/list")
public String getAllDepartment(Model model)
model.addAttribute("departments", repository.findAll());
return "department/list";
when hit define url only "/list" it's working fine and all css and jss working well but when define "/department/list" this url my css and jss not load.
in my view
here is my base.html
<html dir="ltr" lang="en" class="no-outlines"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Meetup</title>
<link rel="stylesheet" th:href="@assets/css/style.css">
</head>
<body>
<div class="wrapper">
<main class="main--container">
<section class="main--content"
layout:fragment="content">
</section>
</main>
</div>
<script th:src="@assets/js/jquery.min.js"></script>
<script th:src="@assets/js/main.js"></script>
</body>
</html>
here is my list.html
<!doctype html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~base">
<head>
<title>Department</title>
</head>
<body>
<section class="main--content" layout:fragment="content">
<div class="row gutter-20">
<div class="col-md-12">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Department Information</h3>
</div>
<div class="records--list" data-title="Orders Listing">
<table id="recordsListView">
<thead>
<tr>
<th>Order No</th>
<th>Order ID</th>
<th>Purchesed On</th>
<th>Customer Name</th>
<th>Ship To</th>
<th>Total Price</th>
<th>Payment</th>
<th>Status</th>
<th class="not-sortable">Actions</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
here is my project file structure
html css spring-boot thymeleaf
add a comment |
up vote
0
down vote
favorite
i have a base.html where i have put on my all css and js file and it's working fine when i define url without "/".
Here is my code
my controller
@GetMapping("/department/list")
public String getAllDepartment(Model model)
model.addAttribute("departments", repository.findAll());
return "department/list";
when hit define url only "/list" it's working fine and all css and jss working well but when define "/department/list" this url my css and jss not load.
in my view
here is my base.html
<html dir="ltr" lang="en" class="no-outlines"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Meetup</title>
<link rel="stylesheet" th:href="@assets/css/style.css">
</head>
<body>
<div class="wrapper">
<main class="main--container">
<section class="main--content"
layout:fragment="content">
</section>
</main>
</div>
<script th:src="@assets/js/jquery.min.js"></script>
<script th:src="@assets/js/main.js"></script>
</body>
</html>
here is my list.html
<!doctype html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~base">
<head>
<title>Department</title>
</head>
<body>
<section class="main--content" layout:fragment="content">
<div class="row gutter-20">
<div class="col-md-12">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Department Information</h3>
</div>
<div class="records--list" data-title="Orders Listing">
<table id="recordsListView">
<thead>
<tr>
<th>Order No</th>
<th>Order ID</th>
<th>Purchesed On</th>
<th>Customer Name</th>
<th>Ship To</th>
<th>Total Price</th>
<th>Payment</th>
<th>Status</th>
<th class="not-sortable">Actions</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
here is my project file structure
html css spring-boot thymeleaf
Is everything working fine inbase.html
?
– Avijit Barua
Nov 11 at 6:39
yes working fine when url define "/list" or "/department" but when i define "/department/list" this url then css and jss not loaded
– kazi
Nov 11 at 6:48
Actually I am little confused! In which html page css is not loading ??base.html
orlist.html
?
– Avijit Barua
Nov 11 at 6:58
i think base.html because all css and js loaded from it and i have decorated base layout from list.html
– kazi
Nov 11 at 7:19
Try using allhtml
page page in same level. That means all html page in one folder for testing purpose!
– Avijit Barua
Nov 11 at 7:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i have a base.html where i have put on my all css and js file and it's working fine when i define url without "/".
Here is my code
my controller
@GetMapping("/department/list")
public String getAllDepartment(Model model)
model.addAttribute("departments", repository.findAll());
return "department/list";
when hit define url only "/list" it's working fine and all css and jss working well but when define "/department/list" this url my css and jss not load.
in my view
here is my base.html
<html dir="ltr" lang="en" class="no-outlines"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Meetup</title>
<link rel="stylesheet" th:href="@assets/css/style.css">
</head>
<body>
<div class="wrapper">
<main class="main--container">
<section class="main--content"
layout:fragment="content">
</section>
</main>
</div>
<script th:src="@assets/js/jquery.min.js"></script>
<script th:src="@assets/js/main.js"></script>
</body>
</html>
here is my list.html
<!doctype html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~base">
<head>
<title>Department</title>
</head>
<body>
<section class="main--content" layout:fragment="content">
<div class="row gutter-20">
<div class="col-md-12">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Department Information</h3>
</div>
<div class="records--list" data-title="Orders Listing">
<table id="recordsListView">
<thead>
<tr>
<th>Order No</th>
<th>Order ID</th>
<th>Purchesed On</th>
<th>Customer Name</th>
<th>Ship To</th>
<th>Total Price</th>
<th>Payment</th>
<th>Status</th>
<th class="not-sortable">Actions</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
here is my project file structure
html css spring-boot thymeleaf
i have a base.html where i have put on my all css and js file and it's working fine when i define url without "/".
Here is my code
my controller
@GetMapping("/department/list")
public String getAllDepartment(Model model)
model.addAttribute("departments", repository.findAll());
return "department/list";
when hit define url only "/list" it's working fine and all css and jss working well but when define "/department/list" this url my css and jss not load.
in my view
here is my base.html
<html dir="ltr" lang="en" class="no-outlines"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Meetup</title>
<link rel="stylesheet" th:href="@assets/css/style.css">
</head>
<body>
<div class="wrapper">
<main class="main--container">
<section class="main--content"
layout:fragment="content">
</section>
</main>
</div>
<script th:src="@assets/js/jquery.min.js"></script>
<script th:src="@assets/js/main.js"></script>
</body>
</html>
here is my list.html
<!doctype html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~base">
<head>
<title>Department</title>
</head>
<body>
<section class="main--content" layout:fragment="content">
<div class="row gutter-20">
<div class="col-md-12">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Department Information</h3>
</div>
<div class="records--list" data-title="Orders Listing">
<table id="recordsListView">
<thead>
<tr>
<th>Order No</th>
<th>Order ID</th>
<th>Purchesed On</th>
<th>Customer Name</th>
<th>Ship To</th>
<th>Total Price</th>
<th>Payment</th>
<th>Status</th>
<th class="not-sortable">Actions</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
here is my project file structure
html css spring-boot thymeleaf
html css spring-boot thymeleaf
asked Nov 11 at 5:52
kazi
178
178
Is everything working fine inbase.html
?
– Avijit Barua
Nov 11 at 6:39
yes working fine when url define "/list" or "/department" but when i define "/department/list" this url then css and jss not loaded
– kazi
Nov 11 at 6:48
Actually I am little confused! In which html page css is not loading ??base.html
orlist.html
?
– Avijit Barua
Nov 11 at 6:58
i think base.html because all css and js loaded from it and i have decorated base layout from list.html
– kazi
Nov 11 at 7:19
Try using allhtml
page page in same level. That means all html page in one folder for testing purpose!
– Avijit Barua
Nov 11 at 7:26
add a comment |
Is everything working fine inbase.html
?
– Avijit Barua
Nov 11 at 6:39
yes working fine when url define "/list" or "/department" but when i define "/department/list" this url then css and jss not loaded
– kazi
Nov 11 at 6:48
Actually I am little confused! In which html page css is not loading ??base.html
orlist.html
?
– Avijit Barua
Nov 11 at 6:58
i think base.html because all css and js loaded from it and i have decorated base layout from list.html
– kazi
Nov 11 at 7:19
Try using allhtml
page page in same level. That means all html page in one folder for testing purpose!
– Avijit Barua
Nov 11 at 7:26
Is everything working fine in
base.html
?– Avijit Barua
Nov 11 at 6:39
Is everything working fine in
base.html
?– Avijit Barua
Nov 11 at 6:39
yes working fine when url define "/list" or "/department" but when i define "/department/list" this url then css and jss not loaded
– kazi
Nov 11 at 6:48
yes working fine when url define "/list" or "/department" but when i define "/department/list" this url then css and jss not loaded
– kazi
Nov 11 at 6:48
Actually I am little confused! In which html page css is not loading ??
base.html
or list.html
?– Avijit Barua
Nov 11 at 6:58
Actually I am little confused! In which html page css is not loading ??
base.html
or list.html
?– Avijit Barua
Nov 11 at 6:58
i think base.html because all css and js loaded from it and i have decorated base layout from list.html
– kazi
Nov 11 at 7:19
i think base.html because all css and js loaded from it and i have decorated base layout from list.html
– kazi
Nov 11 at 7:19
Try using all
html
page page in same level. That means all html page in one folder for testing purpose!– Avijit Barua
Nov 11 at 7:26
Try using all
html
page page in same level. That means all html page in one folder for testing purpose!– Avijit Barua
Nov 11 at 7:26
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Solution : You should replace assets/js/jquery.min.js
with /assets/js/jquery.min.js
. You've missed the / at the beginning.
In your case is taking the relative url: it will try http://localhost:8080/department/list/assets/js/jquery.min.js
and this resource does not exist.
You should use / at the beginning of your path to tell spring that you need absolute resource.The returned resource will be http://localhost:8080/assets/js/jquery.min.js
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Solution : You should replace assets/js/jquery.min.js
with /assets/js/jquery.min.js
. You've missed the / at the beginning.
In your case is taking the relative url: it will try http://localhost:8080/department/list/assets/js/jquery.min.js
and this resource does not exist.
You should use / at the beginning of your path to tell spring that you need absolute resource.The returned resource will be http://localhost:8080/assets/js/jquery.min.js
add a comment |
up vote
1
down vote
Solution : You should replace assets/js/jquery.min.js
with /assets/js/jquery.min.js
. You've missed the / at the beginning.
In your case is taking the relative url: it will try http://localhost:8080/department/list/assets/js/jquery.min.js
and this resource does not exist.
You should use / at the beginning of your path to tell spring that you need absolute resource.The returned resource will be http://localhost:8080/assets/js/jquery.min.js
add a comment |
up vote
1
down vote
up vote
1
down vote
Solution : You should replace assets/js/jquery.min.js
with /assets/js/jquery.min.js
. You've missed the / at the beginning.
In your case is taking the relative url: it will try http://localhost:8080/department/list/assets/js/jquery.min.js
and this resource does not exist.
You should use / at the beginning of your path to tell spring that you need absolute resource.The returned resource will be http://localhost:8080/assets/js/jquery.min.js
Solution : You should replace assets/js/jquery.min.js
with /assets/js/jquery.min.js
. You've missed the / at the beginning.
In your case is taking the relative url: it will try http://localhost:8080/department/list/assets/js/jquery.min.js
and this resource does not exist.
You should use / at the beginning of your path to tell spring that you need absolute resource.The returned resource will be http://localhost:8080/assets/js/jquery.min.js
answered Nov 11 at 7:40
Adina
1,1921210
1,1921210
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246212%2fcss-and-js-url-not-working-on-base-file-thymeleaf-by-layout-decorate%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is everything working fine in
base.html
?– Avijit Barua
Nov 11 at 6:39
yes working fine when url define "/list" or "/department" but when i define "/department/list" this url then css and jss not loaded
– kazi
Nov 11 at 6:48
Actually I am little confused! In which html page css is not loading ??
base.html
orlist.html
?– Avijit Barua
Nov 11 at 6:58
i think base.html because all css and js loaded from it and i have decorated base layout from list.html
– kazi
Nov 11 at 7:19
Try using all
html
page page in same level. That means all html page in one folder for testing purpose!– Avijit Barua
Nov 11 at 7:26