This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

HttpSession

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
i am confused in using httpsession
i am not getting correct method for creating new sessions. all methods are returning existing sessions or if there are no existing sessions then only it retruns or creates new session.
but i want to create new session if there is previous session is available. that means i want to execute two sessions simultaneously.

Thanks
[ April 24, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to use your custom session manager for this. As for Servlet container, A request can belong to only one session at a time.

BTW, if it helps ,
You can invalidate previous session and start new session.
httpSession.invalidate() will close the previous session & then
request.getSession(true) will return you new session

HTH

V
 
Marshal
Posts: 67273
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"saurabhsnaik", please check your private messages for an important administrative matter.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Vishal said is correct.
More specifically, you don't create sessions.
Sessions are created by the container on your behalf.

Maybe if you explain what you're trying to accomplish, someone can suggest a more standard approach.
 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program is about shopping cart
i took arraylist for storing data. user just going to add items in arraylist. and i am going to display it on browser.for this purpose i used the method session.setAttribute() , and by session.getAttribute() method i am going to display the contents.
but problem is e.g suppose i run the program. and added items in cart by creating session and items are Bat, Ball and if simultaneously new user comes that is on another browser and if he adds new items to his shopping cart e.g stumps. but it displays bat,ball,stumps. problem is it takes the last session. i.e it does not create new session for him.
so how to overcome this difficulty. if new user on new browser destroys the previous session then the old user on old browser will have problem.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Vishal mentioned should solve your problem!!

Just use request.getSession(true) in your code.

New session is created by the container when you open a new browser. And there is no question of a 'user' invalidating the previous session.

-Amar
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by saurabh naik:
but problem is e.g suppose i run the program. and added items in cart by creating session and items are Bat, Ball and if simultaneously new user comes that is on another browser and if he adds new items to his shopping cart e.g stumps. but it displays bat,ball,stumps. problem is it takes the last session. i.e it does not create new session for him.



A new user, with a separate browser will always create a new session.
If this list is being shared among different users, I suspect that you're either storing it in context (aka application) scope or, more likely, you've got instance variables in your servlet or JSP that point to this list.

Can you post the code that creates the list and binds it to scope?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are using tabs(IE7) for the second user logins. If it's two seperate browser window no way you should see the same session.
 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Duddiyanda Siraj:
I guess you are using tabs(IE7) for the second user logins. If it's two seperate browser window no way you should see the same session.



I am really sorry.its getting. thats right i m using IE7
thank you all.
why its not coming on tabs ?
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is because the same cookie is being used by both the tabs.
This behaviour is browser dependent.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!