Session 有没有办法在自定义ActionMapper中获取会话映射?

Session 有没有办法在自定义ActionMapper中获取会话映射?,session,struts2,Session,Struts2,我想在Struts2中的自定义ActionMapper中获取/设置会话参数。当我打电话时 Map<String, Object> session = ActionContext.getContext().getSession(); Map session=ActionContext.getContext().getSession(); 在我的自定义MyActionMapper类中,session为null 我做错了什么?我必须配置一些东西才能真正拥有一个会话吗 谢谢,Gregor

我想在Struts2中的自定义ActionMapper中获取/设置会话参数。当我打电话时

Map<String, Object> session = ActionContext.getContext().getSession();
Map session=ActionContext.getContext().getSession();
在我的自定义
MyActionMapper
类中,
session
null

我做错了什么?我必须配置一些东西才能真正拥有一个会话吗


谢谢,Gregor

在我的自定义
ActionMapper中,这实际上是一种很好的方法:

private SessionMap<String, Object> getSession(HttpServletRequest request) {
    SessionMap<String, Object> session = 
        (SessionMap<String, Object>) ActionContext.getContext().getSession();

    if ( session == null ) {
        /* create a sessionMap if we don't already have one. */
        session = new SessionMap<String, Object>(request);
    }
    return session;
}
private SessionMap getSession(HttpServletRequest){
SessionMap会话=
(SessionMap)ActionContext.getContext().getSession();
if(会话==null){
/*如果我们还没有sessionMap,请创建一个sessionMap*/
会话=新会话映射(请求);
}
返回会议;
}
当您使用
ognl#session.USER_键时,如果您使用
getSession
setSession
,它将找不到

最好从下面的语法中获取
SessionMap

SessionMap sessionmap = ActionContext.getContext().get("session") ;
然后它就会正常工作