我在Spring Portlet中使用Spring Web Flow(这在 Portlet 中很重要)
如何从 Web 流中获取会话(HttpSession)对象???
我知道 spring 提供了特殊的变量,比如externalContext
or flowRequestContext
,但我不知道如何从这些对象中获取会话
我在Spring Portlet中使用Spring Web Flow(这在 Portlet 中很重要)
如何从 Web 流中获取会话(HttpSession)对象???
我知道 spring 提供了特殊的变量,比如externalContext
or flowRequestContext
,但我不知道如何从这些对象中获取会话
在 Spring Portlet Webflow 组合中:可以通过 externalContext 访问 sessionMap。对于 portlet,这是由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 对象,但属性可以。