简体   繁体   English

Jtwig如何获取HttpSession / HttpServletRequest?

[英]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. 最近开始使用Jtwig,并且不知道如何轻松获取会话,servletrequest,远程用户等。 In Thymeleaf, for example, it can be done that way: 例如,在Thymeleaf中,可以这样进行:

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

Documentation nor Google was not able to answer my question. 文档或Google都无法回答我的问题。 Probably, this is not implemented (yet?) and i always must put necessary objects manually into the ModelMap? 可能还没有实现(还好吗?),我总是必须手动将必要的对象放到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. 基本上,遵循从请求变量开始的servlet API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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