I have a WEB APP( a .war) that calls a servlet( an independent servlet ) to handle the sessions and the servlet furthur calls another .war; The problem is that the session object that the servlet creates is not accessible to the 2nd war. Is there any way i can get the same session object in the 2nd web app.
Thanks in advance
Sahil
Discussions
Web tier: servlets, JSP, Web frameworks: Accessing Session Object from one application to another..
-
Accessing Session Object from one application to another.. (5 messages)
- Posted by: sahil gupta
- Posted on: March 21 2001 09:47 EST
Threaded Messages (5)
- Accessing Session Object from one application to another.. by Srinivas Janakiraman on March 23 2001 11:28 EST
- Accessing Session Object from one application to another.. by Srinivas Janakiraman on March 23 2001 11:29 EST
- Accessing Session Object from one application to another.. by joseph yi on March 23 2001 19:58 EST
- Accessing Session Object from one application to another.. by Prasath Balakrishnan on March 26 2001 23:14 EST
- Accessing Session Object from one application to another.. by Sonu Gupta on May 07 2001 04:19 EDT
- Accessing Session Object from one application to another.. by Prasath Balakrishnan on March 26 2001 23:14 EST
-
Accessing Session Object from one application to another..[ Go to top ]
- Posted by: Srinivas Janakiraman
- Posted on: March 23 2001 11:28 EST
- in response to sahil gupta
Hi Sahil,
As far as I know each war runs on separate web container and hence separate servlet context. So no direct way to communicate. you can think of serializing the object to a file or to a RDBMS table and retrieve it in the second war.
Srinivas.J -
Accessing Session Object from one application to another..[ Go to top ]
- Posted by: Srinivas Janakiraman
- Posted on: March 23 2001 11:29 EST
- in response to Srinivas Janakiraman
If you are successfull please inform me at janasx1@hotmail.com -
Accessing Session Object from one application to another..[ Go to top ]
- Posted by: joseph yi
- Posted on: March 23 2001 19:58 EST
- in response to sahil gupta
I also had this problem but after some careful thinking, I devised a solution to meet my needs.
My problem was that I wanted to have a single sign on application to create a session object if the user logs in successfully. I needed that session object to be 'shared' across multiple contexts so that the user didn't have to log in for each context. I also did not want to use Tomcat's security schema of realms and such because it didn't really fit in with the infrastructure of where I work. Anyway, here's my solution:
1. In your servlet that makes the session object, store the session object in the ServletContext object with a unique key that can be referenced per user instance. For example, I used the user's IP address as my key so I basically did
HttpSession session = req.getSession(true);
ServletContext sc = getServletConfig().getServletContext();
sc.setAttribute(request.getRemoteAddr(), session);
So if I wanted to get the session from another servlet, I had to
ServletContext sc = getServletConfig().getServletContext().getContext("$contextpath");
HttpSession session = (HttpSession)sc.getAttribute(req.getRemoteAddr());
Try it out. =P There are many issues about this method of doing it. For example, if many users connected through a proxy server, then the servlet would only have once instance of the session for all those users. =( Because my login application was for the intranet, these issues are moot, but if I wanted to develop this for a more public audience, I'd have to devise another scheme to uniquely identify keys I store in the ServletContext object. Let me know how this works out for you =)
-
Accessing Session Object from one application to another..[ Go to top ]
- Posted by: Prasath Balakrishnan
- Posted on: March 26 2001 23:14 EST
- in response to joseph yi
My suggestion is have a bean common to both the applications and store the session object in your bean while the user logs in and retrieve it whenever and wherever you want.
Yes we are working it out thorugh that way and it is fine.
Prasath Balakrishnan
prasathb@yahoo.com -
Accessing Session Object from one application to another..[ Go to top ]
- Posted by: Sonu Gupta
- Posted on: May 07 2001 16:19 EDT
- in response to Prasath Balakrishnan
Can you give me an example of the way you created the bean. Is it a class that you are using and how are you accessing the bean across the war files? Thanks.