Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpSession

 
Saurabh Naik
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 ]
 
Vishal Matere
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65534
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"saurabhsnaik", please check your private messages for an important administrative matter.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 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.
 
Amarender Reddy
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 Redhat VI Editor
  • 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?
 
Duddiyanda Siraj
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 ?
 
Amol Nayak
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!