【问题标题】:Thymeleaf and sessions百里香和会议
【发布时间】:2013-06-05 08:41:19
【问题描述】:

1) 知道的人请提供有关使用 Thymeleaf 模板引擎的页面中的会话的更多信息。

2) Thymeleaf 中默认启用会话,就像在 JSP 中一样?

3) 在 Thymeleaf 中,会话对象有什么限制吗?

4) 在 Thymeleaf 中是否有(或需要)一些特定的结构来处理会话?

在 JSP 中,我们默认使用 session="true",我们必须使用如下内容:

<jsp:directive.page contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" session="false" />

Google 或 Thymeleaf 论坛没有足够的信息来说明这个模板引擎是如何与会话一起工作的。

我的英语基础水平。

【问题讨论】:

    标签: java spring session spring-mvc thymeleaf


    【解决方案1】:

    使用 #httpSession 或 ${session} 对象及其方法来检查 ServletSession 。请确保您正在使用 ExpressionLanguage 进行所有操作。

    Click Here了解更多。

    【讨论】:

      【解决方案2】:

      Thymeleaf 是一个模板引擎,或者可选地(虽然最常用)用作 Spring MVC 中的视图层。作为一个模板引擎,它与会话没有任何关系。它的工作只是处理 EL 并输出标记。

      另一方面,Spring MVC 将允许会话 bean 范围,并且可以让您访问和修改会话。见http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html

      另见: Spring MVC: HTTP session management "equivalent" Spring "session" scope of a bean

      【讨论】:

        【解决方案3】:

        您可以通过 thymelaaf 轻松使用 session。

           session.setAttribute("mySessionAttribute", "someValue");
        

        您可以直接访问会话属性。

        ${#session.getAttribute('mySessionAttribute')}
        

        【讨论】:

          猜你喜欢
          • 2020-12-30
          • 2015-12-09
          • 1970-01-01
          • 2013-09-10
          • 1970-01-01
          • 1970-01-01
          • 2021-12-11
          • 2021-01-09
          相关资源
          最近更新 更多