简体   繁体   中英

Jtwig How to obtain HttpSession / HttpServletRequest?

Recently began using Jtwig and have no idea how to easily obtain session, servletrequest, remote user and so on. In Thymeleaf, for example, it can be done that way:

<span th:text="${#httpServletRequest.remoteUser}"></span>
...
<p th:text="${#httpSession.getValue(...)}"></p>

Documentation nor Google was not able to answer my question. Probably, this is not implemented (yet?) and i always must put necessary objects manually into the ModelMap?

The request object is added to the model for free. For example, to access the remote user:

{{ request.remoteUser }}

To access a session attribute:

{{ request.session.getAttribute('user') }}

Basically, follow the servlet API starting with the request variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM