【发布时间】:2016-05-13 14:06:19
【问题描述】:
我见过this,我正在尝试在页面中设置一个会话,并使用发布请求将其传递给一个方法并打印它。所以这里是 3 个步骤:
第 1 步:在首页设置会话:
@RequestMapping(method=GET, path="/ShowRequestedPlantsInPO") //PS5
public String ShowRequestedPlantsInPO(Model model,HttpSession session){
session.setAttribute("mySessionAttribute", "someValue");
return "dashboard/orders/ShowPOs";
}
第 2 步:在页面中获取会话
<form style='float:left; padding:5px; height:0px' th:object="${p}"
th:method="post"
th:action="@{/dashboard/testSession/th:text=${session.mySessionAttribute} }"
>
<button class="btn btn-default btn-xs" type="submit">
Test Session
</button>
</form>
如您所见,我尝试使用 th:text=${session.mySessionAttribute} 访问我的会话
第三步:获取前一个形式的目标方法中session的值:
@RequestMapping(method=POST, path="/testSession/{email:.+}")
public String testSession(@PathVariable("email") String email) throws Exception {
System.out.println("Invoice is sent to..................."+email);
return "dashboard/orders/Invoice";
}
问题是它不打印会话值“SomeValue” 它唯一打印的是: th:text=${session.mySessionAttribute}
【问题讨论】:
-
@JB Nizet 你能帮我解决这个问题吗?
-
这个语法
th:action="@{/dashboard/testSession/th:text=${session.mySessionAttribute}是完全错误的。
标签: java spring spring-boot thymeleaf