title: Spring MVC: How do I get current url in Thymeleaf
body: <p>I am using <a href="http://www.thymeleaf.org/doc/html/Using-Thymeleaf.html" rel="noreferrer">Thymeleaf Template Engine</a> with Spring Web MVC and I am got stuck while creating url's with the help of current url. Is there any way to get current inside Thymeleaf HTML file? eg: Suppose my current url in my browser address bar is: </p>
  
  <p><code>http://localhost:8080/project/web/category/mobiles</code> </p>
  
  <p>and now I want to make a url like this <code>http://localhost:8080/project/web/category/mobiles/store/samsung</code> </p>
  
  <p>or </p>
  
  <p><code>http://localhost:8080/project/web/category/mobiles?min_price=10&amp;max_price=100</code>. </p>
  
  <p>So I the code will look like this</p>
  
  <pre><code>&lt;a th:with="currentUrl='http://localhost:8080/project/web/category/mobiles'" 
     th:href="@{__${currentUrl}__/__${store.name}__}"&gt;
      Click to More Result
  &lt;/a&gt;
  </code></pre>
  
  <p>Here I am using <code>currentUrl</code> variable with hardcoded url, So I want to some solution for the same. The hardcoded value will not work everytime because I have dynamic categories. </p>
  
  <p>I tried the same with relative url but its not working for me. </p>
  
  <pre><code>&lt;a th:href="@{/store/__${store.name}__}"&gt;Click to More&lt;/a&gt;
  
  //will produce: http://localhost:8080/project/web/store/samsung
  //I want: http://localhost:8080/project/web/category/mobiles/store/samsung
  </code></pre>
  
  <p>Please have a look and let me know if am I doing something wrong.</p>