Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure in Thymeleaf the base URL?

I use Thymeleaf for the templates of a web application.

When I make a link I use a URL like this:

<img class="info" 
    src="../../../resources/img/image.png"
    th:src="@{/resources/img/image.png}" /> 

How can I configure the base URL in Thymeleaf?

I need this because my application runs in the current URL:

http://localhost:8080/myapp

And it works fine, but then it redirects to:

http://www.myapp.com/

Then the images was search in:

http://www.myapp.com/myapp/resources/img/image.png

instead of:

http://www.myapp.com/resources/img/image.png

I want something like:

<property name="baseURL" value="http://www.myapp.com"/>
like image 522
Troncador Avatar asked Sep 06 '13 06:09

Troncador


People also ask

How do I get the URL parameter in Thymeleaf?

Another way of accessing request parameters in thymeleaf is by using #httpServletRequest utility object which gives direct access to javax. servlet. http. HttpServletRequest object.

What is base URL?

The URL found in the address bar of the front page of a website is its base URL. In other words, the common prefix found while navigating inside a given website is known as the base URL. One can select a base URL from the list of those available with help of the URL general properties page.


1 Answers

Try Server-relative URLs:

<img class="info" th:src="@{~/resources/img/image.png}" />

UPD
Actual link to url part of Thymeleaf 2.1. tutorial

like image 82
Ilya Avatar answered Oct 27 '22 14:10

Ilya