facebook

How to pass Session variable to different Webapplication?

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #237281 Reply

    Hi all!

    My conf:
    MyEclipse 4.0 final
    tomcat 5.0.29

    I would like to pass a session variable (user credentials) from application homebase to application test. Both applications were deployed on the same tomcat-server and crosscontext=true for both Applications.

    For example I was setting up a session variable in my request:

    
    request.setAttribute("test", "Hello!!!!!");
    

    Next I’m trying to get the context of app2, and forward this request into this context. I “partitioned” the programcode to debug it, but it is still working without exception.

    
    
    
                ActionServlet actionServlet = this.getServlet();
                if (actionServlet == null) {
                    System.out.println("actionServlet nuull");
                }
                ServletConfig servletConfig = actionServlet.getServletConfig();
                if (servletConfig == null) {
                    System.out.println("servletConfig nuull");
                }
                ServletContext servletContext = servletConfig.getServletContext();
                if (servletContext == null) {
                    System.out.println("servletContext nuull");
                }
    
                ServletContext servletContextTest = servletContext.getContext("/test");
                if (servletContextTest == null) {
                    System.out.println("servletContextTest Null!");
                }
                
                RequestDispatcher reqDis = servletContextTest.getRequestDispatcher("/testSessVar.do");
                if (reqDis == null) {
                    System.out.println("reqDis Null!");
                }
                
                
                try {
                    reqDis.include(request, response);
                } catch (ServletException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch(Exception e)
                {
                    System.out.println(e);
                }
                
    
    

    The called Servlet testSessVar.do is calling a jsp-page called success.jsp.

    
    
    <%@ page language="java" pageEncoding="UTF-8"%>
    
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html locale="true">
      <head>
        <html:base />
        
        <title>success.jsp</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
      </head>
      
      <body>
    <html:form action="/testForward" >
    
    </html:form>
      <bean:write name="test" scope="request"/>
      <html:submit></html:submit>
    
      
      </body>
    </html:html>
    

    My request(test) is showing “Hello!!!!” – so it was possible to pass the Session variable from the context of application1 to application2. 🙂

    My problem is, that the URL in my browser is still showing http://localhost:8080/HomeBase/LOGIN/userLogin.do – so my active Webapplication seems to be the application “Homebase”, not the application “test”.
    However, it is not possible to map a struts-action with the submit-button of the success.jsp.
    (Of course the struts-action-mapping is possible after calling the success.jsp withing the “test”-content […8080:/test/success.jsp])

    How is it possible to change/forward/link to another webapplication without loosing the session variables?

    (When I’m forwarding with struts [context relativ, redirect….], the URL is localhost:8080/test….., but the session variables are gone).

    thx for any help

    greetings
    Martin

    #237415 Reply

    Riyad Kalla
    Member

    Martin,
    This is an excellent question but I think you should ask it on the Struts mailing list in addition to here to make sure you get a reply, I honestly don’t have any suggestion fo ryou (not done cross context before).

    #237580 Reply

    This message has not been recovered.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: How to pass Session variable to different Webapplication?

You must be logged in to post in the forum log in