Question

In an application am using spring + thymeleaf. I want to get the user agent for including cetain files.

 <% 
    String browser = request.getHeader("User-Agent")
%>

i need to get this done in a thymeleaf page.How can i do that. Any help will be appreciated

Was it helpful?

Solution

SHANib's answer didn't work for me. getRequest on ServletRequest has no parameters, at least on my version. However,

<span th:text="${#httpServletRequest.getHeader('User-Agent')}">Agent</span>

worked just fine.

OTHER TIPS

you can access the HttpServletRequest object with #httpServletRequest

So, for example, you can print the user agent like this

 <span th:text="${#httpServletRequest.getRequest('User-Agent')}">Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)</span
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top