Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf: how to get URL attribute value

I can't find any solution for getting attribute from URL using Thymeleaf. For example, for URL:

somesite.com/login?error=true 

I need to get "error" attribute value. Also I'm using SpringMVC, if it could be helpful.

like image 378
Maxim Kolesnikov Avatar asked Jan 25 '13 00:01

Maxim Kolesnikov


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.

How do you get the value of Thymeleaf?

Request parameters can be easily accessed in Thymeleaf views. Request parameters are passed from the client to server like: https://example.com/query?q=Thymeleaf+Is+Great! In the above example if parameter q is not present, empty string will be displayed in the above paragraph otherwise the value of q will be shown.

How do you get the model attribute in Thymeleaf?

In Thymeleaf, these model attributes can be accessed with the following syntax: `${attributeName}` which is a Spring EL expression.


1 Answers

After some investigation I found that it was Spring EL issue actually. So complete answer with null checking is:

<div id="errors" th:if="${(param.error != null) and (param.error[0] == 'true')}">     Input is incorrect </div> 
like image 71
Maxim Kolesnikov Avatar answered Sep 28 '22 13:09

Maxim Kolesnikov