Skip to content

How to use explicit links with Thymeleaf?

I wanted to make and link to external site in Spring+Thymeleaf web application and inserted link like this: <a th:href="@{}">Link</a>

However by clicking the link it tries to point internal location http://localhost/service/ not external website like it supposed to.

Site gives just an error "status":500,"error":"Internal Server Error","message":"The request was rejected because the URL was not normalized."

What’s wrong and how to make absolute links with Thymeleaf?


The problem was that the application was built on top of other Spring+Thymeleaf project. Only way I got link working was like this.

<a th:text="link" th:onclick="|window.location.href='@{}'|"></a>

I know this is not a “real” link and cannot be configure to open with target="_blank" or so but it’s working with this use case.