I'm using spring webflow, but I need to access my HttpSession in a method that's accessed using a transition ==> evaluate expression. (so in the xml file containing my flow) So far I've yet to find a way to actually pass it to my method. I've taken a look at the flowrequestcontext but so far I haven't found a way yet.
问题:
回答1:
I think you don't need to pass it as soon as you pass the RequestContext. You can try this:
public class MyAction extends MultiAction{
public Event myMethod(RequestContext context){
HttpSession session = ((HttpServletRequest)context.getExternalContext().getNativeRequest()).getSession();
...
}
}
回答2:
to insert object (e.g. from flowScope) into session this worked for me:
<evaluate expression="externalContext.sessionMap.put('attributeName', flowScope.myObject)"/>
回答3:
I had a very similar need to access the HttpSession
in a flow. Here's how I did it:
First, take a look at the externalContext
special EL variable:
externalContext
It gives you one of these:
org.springframework.webflow.context.ExternalContext
The ExternalContext
interface provides a method called getNativeRequest()
, which should return to you an HttpRequest
object. (in weblflow 2.0.x at least)
Here is the javadoc: http://static.springsource.org/spring-webflow/docs/2.0.x/javadoc-api/org/springframework/webflow/context/ExternalContext.html#getNativeRequest()
So, that means you should able to craft an expression using something like this:
<evaluate expression="externalContext.nativeRequest.session" result="flowScope.information"/>
As a simple test, you can use an expression like this:
expression="externalContext.nativeRequest.session.id"
to pass your session id to a method.
Of course you can use similar EL to pass the session to methods etc.
回答4:
This worked for me:
<set name="flowRequestContext.externalContext.sessionMap.myId" value="myObject.getId()" />
On the client:
Long id = (Long) request.getSession().getAttribute("myId");
Hope it helps!