Can't access static resource using thymeleaf in specific end points












2















I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE)



This is project structure



enter image description here



As you can see I have html pages (test,test-exchange)
I have one controller to access these two pages:



enter image description here



test.html and test-exchange.html pages are absolutely the same



enter image description here



Here I have tagManager.js in the following dir



/resources/static/js/tagManager.js


In test-exhange.html I can't load this script, but in test.html I can(I mean in developer console I get 404 accessing script).



What is interesting , if I change endpoint to test-exchange.html like this one



enter image description here



Script is loaded successfully.As I understand thymeleaf doesn't allow to have same string in controller to achieve page.
How to fix it???










share|improve this question























  • A small note for improving your questions: please paste the code as code blocks instead of images. Thank you in advance :)

    – Sven Hakvoort
    Nov 21 '18 at 13:24











  • Okey , I will do it in future ,any suggestion about this problem? :)

    – Almas Abdrazak
    Nov 21 '18 at 13:25
















2















I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE)



This is project structure



enter image description here



As you can see I have html pages (test,test-exchange)
I have one controller to access these two pages:



enter image description here



test.html and test-exchange.html pages are absolutely the same



enter image description here



Here I have tagManager.js in the following dir



/resources/static/js/tagManager.js


In test-exhange.html I can't load this script, but in test.html I can(I mean in developer console I get 404 accessing script).



What is interesting , if I change endpoint to test-exchange.html like this one



enter image description here



Script is loaded successfully.As I understand thymeleaf doesn't allow to have same string in controller to achieve page.
How to fix it???










share|improve this question























  • A small note for improving your questions: please paste the code as code blocks instead of images. Thank you in advance :)

    – Sven Hakvoort
    Nov 21 '18 at 13:24











  • Okey , I will do it in future ,any suggestion about this problem? :)

    – Almas Abdrazak
    Nov 21 '18 at 13:25














2












2








2








I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE)



This is project structure



enter image description here



As you can see I have html pages (test,test-exchange)
I have one controller to access these two pages:



enter image description here



test.html and test-exchange.html pages are absolutely the same



enter image description here



Here I have tagManager.js in the following dir



/resources/static/js/tagManager.js


In test-exhange.html I can't load this script, but in test.html I can(I mean in developer console I get 404 accessing script).



What is interesting , if I change endpoint to test-exchange.html like this one



enter image description here



Script is loaded successfully.As I understand thymeleaf doesn't allow to have same string in controller to achieve page.
How to fix it???










share|improve this question














I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE)



This is project structure



enter image description here



As you can see I have html pages (test,test-exchange)
I have one controller to access these two pages:



enter image description here



test.html and test-exchange.html pages are absolutely the same



enter image description here



Here I have tagManager.js in the following dir



/resources/static/js/tagManager.js


In test-exhange.html I can't load this script, but in test.html I can(I mean in developer console I get 404 accessing script).



What is interesting , if I change endpoint to test-exchange.html like this one



enter image description here



Script is loaded successfully.As I understand thymeleaf doesn't allow to have same string in controller to achieve page.
How to fix it???







java spring-boot thymeleaf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 11:33









Almas AbdrazakAlmas Abdrazak

66311023




66311023













  • A small note for improving your questions: please paste the code as code blocks instead of images. Thank you in advance :)

    – Sven Hakvoort
    Nov 21 '18 at 13:24











  • Okey , I will do it in future ,any suggestion about this problem? :)

    – Almas Abdrazak
    Nov 21 '18 at 13:25



















  • A small note for improving your questions: please paste the code as code blocks instead of images. Thank you in advance :)

    – Sven Hakvoort
    Nov 21 '18 at 13:24











  • Okey , I will do it in future ,any suggestion about this problem? :)

    – Almas Abdrazak
    Nov 21 '18 at 13:25

















A small note for improving your questions: please paste the code as code blocks instead of images. Thank you in advance :)

– Sven Hakvoort
Nov 21 '18 at 13:24





A small note for improving your questions: please paste the code as code blocks instead of images. Thank you in advance :)

– Sven Hakvoort
Nov 21 '18 at 13:24













Okey , I will do it in future ,any suggestion about this problem? :)

– Almas Abdrazak
Nov 21 '18 at 13:25





Okey , I will do it in future ,any suggestion about this problem? :)

– Almas Abdrazak
Nov 21 '18 at 13:25












1 Answer
1






active

oldest

votes


















1














This is caused because of the relative mapping of your js files. The page under xxx/test is loaded and tries to load the js file from xxx/js/tagManager.js, but if you are at the url xxx/test/something it will try to load the js file from xxx/test/js/tagManager.js. Thus you will need the mapping from the root of your domain.



You can achieve this with @{/js/tagManager.js} instead of js/tagManager.js.



This would look like this:



<script th:src="@{/js/tagManager.js}"></script>


If anything is unclear feel free to ask






share|improve this answer


























  • do you mean <script th:src="${'/js/tagManager.js'}"></script> this?

    – Almas Abdrazak
    Nov 21 '18 at 13:39











  • @AlmasAbdrazak, yes

    – Sven Hakvoort
    Nov 21 '18 at 13:40











  • @AlmasAbdrazak, but please note that it is with a @ and no quotes inside of the curly brackets

    – Sven Hakvoort
    Nov 21 '18 at 13:41











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',
autoActivateHeartbeat: false,
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%2f53411200%2fcant-access-static-resource-using-thymeleaf-in-specific-end-points%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









1














This is caused because of the relative mapping of your js files. The page under xxx/test is loaded and tries to load the js file from xxx/js/tagManager.js, but if you are at the url xxx/test/something it will try to load the js file from xxx/test/js/tagManager.js. Thus you will need the mapping from the root of your domain.



You can achieve this with @{/js/tagManager.js} instead of js/tagManager.js.



This would look like this:



<script th:src="@{/js/tagManager.js}"></script>


If anything is unclear feel free to ask






share|improve this answer


























  • do you mean <script th:src="${'/js/tagManager.js'}"></script> this?

    – Almas Abdrazak
    Nov 21 '18 at 13:39











  • @AlmasAbdrazak, yes

    – Sven Hakvoort
    Nov 21 '18 at 13:40











  • @AlmasAbdrazak, but please note that it is with a @ and no quotes inside of the curly brackets

    – Sven Hakvoort
    Nov 21 '18 at 13:41
















1














This is caused because of the relative mapping of your js files. The page under xxx/test is loaded and tries to load the js file from xxx/js/tagManager.js, but if you are at the url xxx/test/something it will try to load the js file from xxx/test/js/tagManager.js. Thus you will need the mapping from the root of your domain.



You can achieve this with @{/js/tagManager.js} instead of js/tagManager.js.



This would look like this:



<script th:src="@{/js/tagManager.js}"></script>


If anything is unclear feel free to ask






share|improve this answer


























  • do you mean <script th:src="${'/js/tagManager.js'}"></script> this?

    – Almas Abdrazak
    Nov 21 '18 at 13:39











  • @AlmasAbdrazak, yes

    – Sven Hakvoort
    Nov 21 '18 at 13:40











  • @AlmasAbdrazak, but please note that it is with a @ and no quotes inside of the curly brackets

    – Sven Hakvoort
    Nov 21 '18 at 13:41














1












1








1







This is caused because of the relative mapping of your js files. The page under xxx/test is loaded and tries to load the js file from xxx/js/tagManager.js, but if you are at the url xxx/test/something it will try to load the js file from xxx/test/js/tagManager.js. Thus you will need the mapping from the root of your domain.



You can achieve this with @{/js/tagManager.js} instead of js/tagManager.js.



This would look like this:



<script th:src="@{/js/tagManager.js}"></script>


If anything is unclear feel free to ask






share|improve this answer















This is caused because of the relative mapping of your js files. The page under xxx/test is loaded and tries to load the js file from xxx/js/tagManager.js, but if you are at the url xxx/test/something it will try to load the js file from xxx/test/js/tagManager.js. Thus you will need the mapping from the root of your domain.



You can achieve this with @{/js/tagManager.js} instead of js/tagManager.js.



This would look like this:



<script th:src="@{/js/tagManager.js}"></script>


If anything is unclear feel free to ask







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 13:41

























answered Nov 21 '18 at 13:30









Sven HakvoortSven Hakvoort

2,0251620




2,0251620













  • do you mean <script th:src="${'/js/tagManager.js'}"></script> this?

    – Almas Abdrazak
    Nov 21 '18 at 13:39











  • @AlmasAbdrazak, yes

    – Sven Hakvoort
    Nov 21 '18 at 13:40











  • @AlmasAbdrazak, but please note that it is with a @ and no quotes inside of the curly brackets

    – Sven Hakvoort
    Nov 21 '18 at 13:41



















  • do you mean <script th:src="${'/js/tagManager.js'}"></script> this?

    – Almas Abdrazak
    Nov 21 '18 at 13:39











  • @AlmasAbdrazak, yes

    – Sven Hakvoort
    Nov 21 '18 at 13:40











  • @AlmasAbdrazak, but please note that it is with a @ and no quotes inside of the curly brackets

    – Sven Hakvoort
    Nov 21 '18 at 13:41

















do you mean <script th:src="${'/js/tagManager.js'}"></script> this?

– Almas Abdrazak
Nov 21 '18 at 13:39





do you mean <script th:src="${'/js/tagManager.js'}"></script> this?

– Almas Abdrazak
Nov 21 '18 at 13:39













@AlmasAbdrazak, yes

– Sven Hakvoort
Nov 21 '18 at 13:40





@AlmasAbdrazak, yes

– Sven Hakvoort
Nov 21 '18 at 13:40













@AlmasAbdrazak, but please note that it is with a @ and no quotes inside of the curly brackets

– Sven Hakvoort
Nov 21 '18 at 13:41





@AlmasAbdrazak, but please note that it is with a @ and no quotes inside of the curly brackets

– Sven Hakvoort
Nov 21 '18 at 13:41


















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411200%2fcant-access-static-resource-using-thymeleaf-in-specific-end-points%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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy