将请求从一个应用程序中的操作类转发到另一个应用程序中的jsp后,会话丢失

时间:2013-06-25 20:10:49

标签: session struts2 forward

我正在尝试从application1中的action类转发到application2中的jsp。两个应用程序都在同一个servlet容器(glassfish 2.1)中运行。虽然我可以成功转发并显示jsp,但是在执行ServletActionContext的forward api之前,我无法从application1中设置的会话中检索属性/对象。我在application2中的jsp中打印了sessionID,它与我在application1中打印的id完全匹配。所以,我认为我的会话在这次转变之间没有受到干扰。然后会话变量发生了什么?为什么/如何变为空?

以下是代码:

    request.getSession().setAttribute("commonQuestions", "abc");
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();

    // Change the servletcontext to the second application 
    ServletActionContext.setServletContext(ServletActionContext.getServletContext().getContext("/TYP_PFRS_ETP"));

    // Define request dispatcher for resource in second application
    RequestDispatcher rd = 
        ServletActionContext.getServletContext().getRequestDispatcher("/jsp/helloworld.jsp");

    rd.forward(request, response);

0 个答案:

没有答案