Home arrow static arrow Java Programming [Archive] - Question about javax.servlet.http.HttpSession
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Question about javax.servlet.http.HttpSession
This topic has 11 replies on 1 page.

Posts:370
Registered: 8/17/02
Question about javax.servlet.http.HttpSession  
Jul 11, 2004 12:48 PM



 
ok I got a few ? about this class... now from what the API's tell me HttpSession creates a session with the browser.... and generates a unique ID...

?1 when the session is created does the borwser store this session.. so upon the next reqest when I ask the browser for the session ID it will give me the same one???

?2 if ? one is correct.. is this "session" stored in cookie form?

?3 if ? one is correct then is there anyway to invalidate a session?

I think that is all for now I will let you know if I think of any more..
 

Posts:370
Registered: 8/17/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:29 PM (reply 1 of 11)



 
Never mind... I think I figured it out on my own....from the way the API sounds... a session is infact a cookie stored on the system, which can be a good and bad thing, there is a method to invalidate the session also.. Last but not least.. If a session is persisting as a cookie I would be able to check it via each request... but if there is no cookie support it looks like I would have to rewrite a URL with a session=session val..
 

Posts:370
Registered: 8/17/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:30 PM (reply 2 of 11)



 
Thanks NE way
 

Posts:370
Registered: 8/17/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:31 PM (reply 3 of 11)



 
By the way I would just like to say this forum ROCKs, I would not be able to build the system I am building today without help of this forum thanks guys :-)
 

Posts:1,183
Registered: 1/23/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:32 PM (reply 4 of 11)



 
if there is no cookie support it looks like I would have to rewrite a URL with a session=session val..

Your servlet container of choice should support URL rewrite automatically (most can be configured explicitly to use cookies or rewriting, some automatically try cookies and fall back to rewriting).

The session object lives on the server, so you can invalidate it regardless of how you choose to manage the sessiong ID in the conversation with the browser.

 

Posts:6,147
Registered: 11/9/00
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:38 PM (reply 5 of 11)



 
Never mind... I think I figured it out on my
own....from the way the API sounds... a session is
infact a cookie stored on the system,

Well, to be more exact a session is associated with a random session-id which is copied to a cookie in the browser.

Then every time the browser sends subsequent messages the server detects the cookie and finds the session by looking in up in a hash table.

Or, if cookies are disabled, the browser may code the session id into any URLs on the page that point back to the server.
 

Posts:370
Registered: 8/17/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:44 PM (reply 6 of 11)



 
I have a question again...
see the way things work for me is that upon each data request, I do a request.getSession(), and then I take that session ID and query a database, which in turn will pump out a user name which I may query the rest of my database with... upon inital log in the session ID in stored in a table with the usename... will getSession() involk a new session or will it just repeat back to me the session that I have used previously.. I have another ? also then.. do you have to create a new session to get request.getSession to work??? I can probably find this out by reading the API though... you can also set the session to invalidate at a certain time right....
 

Posts:370
Registered: 8/17/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:54 PM (reply 7 of 11)



 
can I get code on how a session is actually created?? or is it created upon the first page request a borwser makes... this is kinda confuses me...
 

Posts:6,147
Registered: 11/9/00
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 1:59 PM (reply 8 of 11)



 
The session is created when you do a request.getSession(true) and there isn't an existing valid session id in the request's cookies or parameters.

The response for the transaction will then contain an add cookie header.
 

Posts:370
Registered: 8/17/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 2:04 PM (reply 9 of 11)



 
so request.getSession(true), creates a NEW session and request.getSession() will just return the current session? is this correct???
 

Posts:1,183
Registered: 1/23/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 2:14 PM (reply 10 of 11)



 
Both request.getSession(true) and request.getSession() do exactly the same thing, i.e. return the current session, creating one if necessary.
 

Posts:370
Registered: 8/17/02
Re: Question about javax.servlet.http.HttpSession  
Jul 11, 2004 2:17 PM (reply 11 of 11)



 
humm that is smart... I gotta go thankx for the help, bye
 
This topic has 11 replies on 1 page.