【问题标题】:Cannot read session value from emmbeded html page thymeleaf- spring boot无法从嵌入的 html 页面 thymeleaf-spring boot 读取会话值
【发布时间】:2020-05-02 07:21:36
【问题描述】:

我正在尝试读取 html 中的会话值。它工作正常,但是当我尝试从另一个页面读取相同的会话值时,没​​有任何返回

<script> 
$(function(){
  $("#header").load("./common/header.html"); 
});
</script> 
<div id="header"></div>

我将&lt;p th:text="${#session.getAttribute('username')}"&gt; . &lt;/p&gt; 放在标题页内,但没有出现任何内容,尽管它在主 html 页面内工作正常。

【问题讨论】:

    标签: spring-boot thymeleaf httpsession


    【解决方案1】:

    使用 session.getParameter('username') 而不是 session.getAttribute('username'),因为您正在阅读 html 页面中的用户名。

    【讨论】:

    • 我做了,但我得到了相同的结果(空字符串)
    【解决方案2】:

    希望它会奏效。

    <p th:text="${session.username}"> . </p>
    

    【讨论】:

      猜你喜欢
      • 2017-12-10
      • 1970-01-01
      • 2021-09-16
      • 1970-01-01
      • 2019-10-08
      • 2019-09-16
      • 2018-05-08
      • 2018-11-01
      • 2017-04-15
      相关资源
      最近更新 更多