Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top