【问题标题】:Accessing session from Spring Web Flow从 Spring Web Flow 访问会话
【发布时间】:2014-07-23 15:01:05
【问题描述】:
我在 Spring Portlet 中使用 Spring Web Flow(这在 Portlet 中很重要)
如何从网络流中获取会话(HttpSession)对象???
我知道 spring 提供了特殊的变量,例如 externalContext 或 flowRequestContext,
但我不知道如何从这些对象中获取会话
【问题讨论】:
标签:
java
spring
spring-webflow
spring-portlet-mvc
【解决方案1】:
在 Spring Portlet Webflow 组合中:
您可以通过 externalContext 访问 sessionMap。对于 porlets,这是由PortletExternalContext 实现的,它有两个可用的会话映射:globalSessionMap 和 sessionMap。
您可以通过以下方式访问它:
<evaluate expression="externalContext.globalSessionMap.yourSessionAttribute" result="store it somewhere"/>
<evaluate expression="externalContext.sessionMap.yourSessionAttribute" result="store it somewhere"/>
在 ServletContext 中,这些映射返回相同的值。
更新:
如果你需要显式访问 session(portlet session) 本身而不是上面提到的通过 sessionMap 的属性,你可以得到它:
<evaluate expression="externalContext.nativeRequest.portletSession" result="store this session object somewhere"/>
这里的 nativeRequest 对象是PortletRequest 对象。
说了这么多,如果属性放在portlet session 中的APPLICATION_SCOPE 中,那么它们可以在servlet session 范围内访问。
我怀疑您是否可以像这样获得 HttpSession 对象,但属性可以。