I am confused with cookies and using session in servlets in jsp's and servlets. I have 3 questions.
1. I am creating a session for a user in my servlet A and then putting a few values in the session object. Then if the user accesses another servlet B in the same domain, will the servlet be able to read the values. Will the same session object be available to the servlet B.?
2. If I have 5 tabs open containg the different jsp pages of the same server(or domain). Will the method sessio.lastAccessed() for all the 5 tabs return the same value?
3. Can expiry be set for a session object? If yes, how?
0
votes
1 Answers
1
votes
yes, they will share the session
yes, I believe tabs always share a session, but multiple windows will depend on the browser -- you can have multiple instances of IE (separate windows), for example, and they won't.
yes, by setting session-config/session-timeout in web.xml (number of minutes, see below)
<session-config>
<session-timeout>15</session-timeout>
</session-config>
also, to set the session timeout programmatically, use this method:
HttpSession session
session.setMaxInactiveInterval(int interval)
where interval is measured in seconds.