简体   繁体   中英

session.getAttribute returns null on disabling cookies

Can anyone please tell me why request.getSession().getAttribute(SESSIONUSER) returns null when i disable cookies?

I also can't understand that here

Cookie[] cookies = request.getCookies();
Cookie thisCookie = cookies[0];
int age = thisCookie.getMaxAge();  
System.out.println(age);

age comes out to be -1 still the session expires after 10 hours or so? Why is this so?

Your HTTPSession is tracked using jsessionid. It is maintained in a cookie. So when the client is sending the second request to the server, it is expected to send the jsessionid. Or else, Server cannot track the session. In short, your session is created during request.getSession() freshly everytime. Therefore, you don't see your any objects in it.

What "-1" means:
This means the the cookie should be alive till the browser is closed. If it is there for 10hrs it means your browser is not closed for 10hours.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM