Skip to content
Advertisement

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="@{https://example.com}">Link</a>

However by clicking the link it tries to point internal location http://localhost/service/https://example.com not external website https://example.com 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?

Advertisement

Answer

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='@{https://example.com}'|"></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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement