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
enter image description here










share|improve this question





















  • 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 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










  • 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














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
enter image description here










share|improve this question





















  • 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 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










  • 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












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
enter image description here










share|improve this question













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
enter image description here







html css spring-boot thymeleaf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 5:52









kazi

178




178











  • 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 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










  • 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
















  • 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 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










  • 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















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












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






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    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

























    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






    share|improve this answer
























      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






      share|improve this answer






















        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 7:40









        Adina

        1,1921210




        1,1921210



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3