This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Pass data between Sessions - How to?

 
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.
 
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?
 
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.
 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • 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?
 
Ranch Hand
Posts: 644
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?
 
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?
 
Ranch Hand
Posts: 2108
  • 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
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • 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: 2108
  • 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
 
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.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic