Вопрос

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

Это было полезно?

Решение

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.

Другие советы

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top