Session Struts2-重定向后会话丢失

Session Struts2-重定向后会话丢失,session,jakarta-ee,redirect,struts2,httpsession,Session,Jakarta Ee,Redirect,Struts2,Httpsession,我正在开发一个基于Struts2say CNG的Java EE web应用程序。在特定点,用户被重定向到支付网关,比如IM.com,然后IM重定向到CNG的操作。侦听器在检查会话变量的每个操作之前运行,并在从IM.com返回后显示null值 为什么会发生这种情况?如何处理此问题,以便在重定向到另一个应用程序后保留会话 编辑: 我在一个动作中这样设置会话: SessionMap<String, Object> sessionMap = (SessionMap<String, Ob

我正在开发一个基于Struts2say CNG的Java EE web应用程序。在特定点,用户被重定向到支付网关,比如IM.com,然后IM重定向到CNG的操作。侦听器在检查会话变量的每个操作之前运行,并在从IM.com返回后显示null值

为什么会发生这种情况?如何处理此问题,以便在重定向到另一个应用程序后保留会话

编辑:

我在一个动作中这样设置会话:

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) ActionContext.getContext().getSession();

sessionMap.put("userID","1234");
IM,成功后付款/交易重定向到我的应用程序-cng.com/receivePayment?p=4321

在检查会话中用户ID的每个操作之前运行的侦听器:

 public String intercept(ActionInvocation invocation) throws Exception {
            // TODO Auto-generated method stub

            final ActionContext context = invocation.getInvocationContext();
            HttpServletResponse response = (HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE);

            SessionMap<String,Object> sessionMap = (SessionMap<String,Object>)ActionContext.getContext().getSession();
            String m = invocation.getInvocationContext().getName();
            System.out.println(sessionMap.get("userID"));
            return invocation.invoke();

            }

当IM重定向回CNG时,拦截器将运行并打印空值,即我丢失了会话变量。

当您重定向到另一个域时,会话本身将过期。您需要在浏览器中将会话另存为cookie。您也可以在操作中实现同样的功能。发布一些代码,因为不清楚您的要求。@RomanC刚刚更新!可能您的操作不需要该拦截器,除非您知道会话为空。@RomanC I添加该拦截器是为了禁用浏览器缓存和随后的会话管理。
 public String intercept(ActionInvocation invocation) throws Exception {
            // TODO Auto-generated method stub

            final ActionContext context = invocation.getInvocationContext();
            HttpServletResponse response = (HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE);

            SessionMap<String,Object> sessionMap = (SessionMap<String,Object>)ActionContext.getContext().getSession();
            String m = invocation.getInvocationContext().getName();
            System.out.println(sessionMap.get("userID"));
            return invocation.invoke();

            }