• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass data between Sessions - How to?

 
Rajesh Manohar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Caine Lai
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
App servers usually persist session data writing to database, so maybe it looks better than file?
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it safe to assume yu have two sessions because ur application consists of more than one war file? Is that the case?
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic