Can't access static resource using thymeleaf in specific end points
I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE
)
This is project structure
As you can see I have html pages (test,test-exchange
)
I have one controller to access these two pages:
test.html and test-exchange.html
pages are absolutely the same
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
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
add a comment |
I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE
)
This is project structure
As you can see I have html pages (test,test-exchange
)
I have one controller to access these two pages:
test.html and test-exchange.html
pages are absolutely the same
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
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
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
add a comment |
I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE
)
This is project structure
As you can see I have html pages (test,test-exchange
)
I have one controller to access these two pages:
test.html and test-exchange.html
pages are absolutely the same
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
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
I have basic Spring Boot application with thymeleaf starter.(2.0.1.RELEASE
)
This is project structure
As you can see I have html pages (test,test-exchange
)
I have one controller to access these two pages:
test.html and test-exchange.html
pages are absolutely the same
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
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
java spring-boot thymeleaf
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
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%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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
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.
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%2f53411200%2fcant-access-static-resource-using-thymeleaf-in-specific-end-points%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
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