Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

doubts on session creation  RSS feed

 
arul micheal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can you please clarify my doubts on session creation?

I have created

I red an information about the session in a book that if you use the "request.getSession(true)", the new sessionid will be created otherwise it will use the existing id.Based on that i have created two files (login.jsp and HelloServlet.java). when i click on submit button in login page,the control has to go to helloservlet. the code for the files given below:

1. login.jsp

HttpSession sessions=request.getSession(true);
out.println("ession.getId:"+sessions.getId());

2. HelloServlet.java

HttpSession sessions=request.getSession(true);
out.println("ession.getId:"+sessions.getId());


Both of them are displaying the same SessionID.

As the the information given in the book, the sessionId should be
created separately.
I don't know why it is giving the same id. or did i make mistake in code?


Does anybody clarify my doubt?


Thanks
Arulraj
[ August 16, 2007: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'true' argument specifies that getSession should create one if one doesn't already exist, otherwise return the existing one.

You're not going to be able to have more than one session for a user.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The place to look is the API. When you pass the value 'true' a Session is created if one does not already exist. It says nothing about the session ID, however I believe that in your case the session already exists so a new one is not created.

In practice the management of session IDs is container specific, which is an alternate way of saying "Don't count on any particular type of behaviour, it isn't guaranteed". For instance I believe that some servers will reuse session IDs with the same client, others will always create a new session ID, even with the same client.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!