| Author |
Question on sessions and cookies
|
muthu kumaran
Ranch Hand
Joined: Oct 26, 2004
Posts: 56
|
|
Hi Can anyone tell me on what would happen to the session object when they have these following settings 1) session.setMaxInactiveInterval(-1) 2) <session-config> <session-timeout>0</session-timeout> </session-config> 3) <session-config> <session-timeout>-1</session-timeout> <session-config> 4)What is the value to be used for setMaxAge() on the cookie object so that it can stay on the client forever ? 5) Though not related to sessions/cookies..I have read in some places that the order of the elements appearing in DD has significance What is this order and what would happen if those elements are not specified in that order ?
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
About 1,2,3,4 you can search yourself in the API and spec. It's a good exercice. Concerning 5, it mays influence a few things. For example, the servlets with a <load-at-startup> set the the same number will be loaded in the order they have been defined in web.xml. (But I think it depends on the container) The way listeners and filters are loaded is also related to the order.
|
[My Blog]
All roads lead to JavaRanch
|
 |
muthu kumaran
Ranch Hand
Joined: Oct 26, 2004
Posts: 56
|
|
Thanks Satou , But my doubt on the cookies question still stands. In the spec , for the setMaxAge(int expiry) function , it is specified that 0 - cookie is deleted <0 - cookie not persisted >0 - cookie stays for so many seconds on the client. But is it possible for the cookie to stay forever(i.e. remain active forever) on the client ?? If so what is the value to be specified ? {There is a instance in HFSJ where it is mentioned that cookies can be made to stay active forever on the client )
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
I don't know about staying forever, but setMaxAge takes an integer, which should be enough to make it persistent for many years If you want to keep some information forever, I think you should use something different. Like a DB. [ January 26, 2006: Message edited by: Satou kurinosuke ]
|
 |
Vishnu Prakash
Ranch Hand
Joined: Nov 15, 2004
Posts: 1026
|
|
If you want to keep some information forever, I think you should use something different. Like a DB.
I didn't get you here. He is looking for storing the information on the client(browser) for ever and sending them back to the server with each request. In what way DB pictures here.
|
Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
|
 |
mayank jamindar
Ranch Hand
Joined: Aug 01, 2005
Posts: 38
|
|
Dear muthu kumaran, 1)Session will Never expire. 2)Session expires as soon as created, practically session can not be created. 3) Session will Never expire. 4) Anything < 0, it will make your cookie never to destroy. 5) IF you change the order of Listners, filters, Servlets: it affects the Order of Instantiation, or Call.BUT IF you at random shuffle any element with some different element, say error-page put before servlet element, your app. Sever will complain at startup, that the file is wrong, as its checked against DTD. I think that answers you. Do reply back, Mayank
|
 |
muthu kumaran
Ranch Hand
Joined: Oct 26, 2004
Posts: 56
|
|
Hi Mayank, Thanks for u'r answers. For the 4th question on cookies," Anything < 0, it will make your cookie never to destroy" is not true coz the spec says if the setMaxAge() has a negative value, then the cookie will not be persisted and would be deleted when the browser exits !!
|
 |
Jay Tse
Greenhorn
Joined: Aug 12, 2005
Posts: 11
|
|
Hi Mayank, Also answer (3) is not correct. If the <session-timeout> is set to "0" or "-1" in the DD, the session will never expire. In the case of a servlet, setMaxInactiveInterval has to be set to "-1" only in order for the session to not expire. Setting it to "0" will expire the session immediately. The DD and servlet are not consistent when it comes to setting the timeout of the session. I learned this by answering one of the coffee cram exams in HFSJ.
|
 |
 |
|
|
subject: Question on sessions and cookies
|
|
|