Spring MVC: How do I get current url in Thymeleaf

If the requested url is for example : http://localhost:8080/my-page

I could get this value: /my-page using this: httpServletRequest.requestURI

For example, if you have to load some resource , you can use:

<script th:src="@{|${#httpServletRequest.requestURI}/main.js|}"></script>

And renderized html will be:

<script src="/my-page/main.js"></script>

Oh I got the solution for this. I missed the {#httpServletRequest.requestURI} in the documentation.

Here is the solution which is working for me:

<a th:href="@{__${#httpServletRequest.requestURI}__/store/__${store.name}__}">Click to More</a>
//Will produce: http://localhost:8080/project/web/category/mobiles/store/samsung

You can get the current URL using two single ' quotes. Example:

<a th:href="@{''(lang=de)}">Deutsch</a>

Note that this unfortulately does not include existing URL parameters.