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.
Another way of accessing request parameters in thymeleaf is by using #httpServletRequest utility object which gives direct access to javax. servlet. http. HttpServletRequest object.
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.
In Thymeleaf, these model attributes can be accessed with the following syntax: `${attributeName}` which is a Spring EL expression.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With