aspose file tools*
The moose likes Servlets and the fly likes Pass data between Sessions - How to? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Pass data between Sessions - How to?" Watch "Pass data between Sessions - How to?" New topic
Author

Pass data between Sessions - How to?

Rajesh Manohar
Greenhorn

Joined: Sep 22, 2005
Posts: 9
Consider there are 2 sessions created in a web application. How do i pass the data between the sessions.
For example;

Session1 has one attribute called preferredColor with value RED.
The data has to be passed to Session2.

Note: ServletContext should not be used for intermediate storage because I donot want the value to be available to others.
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
I don't see any way how to do this.
Maybe you can write this value to file on filesystem, each session than can read this. How you want recognize which session should do this?


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Caine Lai
Greenhorn

Joined: Sep 21, 2005
Posts: 15
No offense, but writing to a file is a horrible idea. Why don't you just implement a checking mechanism in the servlet context object that makes sure you get the correct data for the sessions you are trying to share data between? It doesn't necessarily have to be available to everyone. Just make sure your code does the necessary checks before handing the data out.


Online collaboration made simple: <a href="http://www.rallypointhq.com" target="_blank" rel="nofollow">http://www.rallypointhq.com</a>
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

App servers usually persist session data writing to database, so maybe it looks better than file?


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

Its quite interesting to have 2 sessions, I normally don't see that kind of application, can you elaborate more why do you need 2 sessions?
Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
Is it safe to assume yu have two sessions because ur application consists of more than one war file? Is that the case?


SCJP 1.4, SCWCD 1.4
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
i think this is a security issue

eventually, the bottom of this is identity of the process doing the transaction

so you can use servlet context attributes, along with security measures
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Originally posted by Rajesh Manohar:
Consider there are 2 sessions created in a web application. How do i pass the data between the sessions.
For example;

Session1 has one attribute called preferredColor with value RED.
The data has to be passed to Session2.

Note: ServletContext should not be used for intermediate storage because I donot want the value to be available to others.



Why not make session1 pass the preferredColor to some inermediate class (which could be a singelton ) and the make the second session session2 to read from the intermediate class.


Groovy
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
Originally posted by Pradip Bhat:



Why not make session1 pass the preferredColor to some inermediate class (which could be a singelton ) and the make the second session session2 to read from the intermediate class.


but he said 'Note: ServletContext should not be used for intermediate storage because I donot want the value to be available to others.'

So anyone would be able to read that intermediate class, or physical file, or database entry, unless you implement some sort of security
Keith Pitty
Ranch Hand

Joined: Sep 22, 2005
Posts: 32
Rajesh,

It would be helpful if you explained more about the context of the two sessions. Do you envisage both sessions being for the same user, perhaps the second being created when the user logs on after the first one times out?

If so, it would make sense to store the preferred colour for each user in a database so that it can be retrieved when subsequent sessions are created for the same user.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass data between Sessions - How to?
 
Similar Threads
Passing values between servlets
Simple DataAccess Design Question
Synchronization between Sessions
How to integrate two web applications having two different context paths
Communicate between two Sessions