• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

HttpSession

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is because the same cookie is being used by both the tabs.
This behaviour is browser dependent.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic