문제

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