01 session tracking

459 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
459
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

01 session tracking

  1. 1. Session Tracking<br />DhrubojyotiKayal<br />
  2. 2. HTTP is stateless<br />Need to maintain identify clients sending requests<br />javax.servlet.http.HttpSession is an interface that provides a way to identify a user across more than one page request or visit to a web site<br />Useful in saving user detail, shopping carts<br />Other mechanisms – URL rewrite, Cookies – dangerous, security issues.<br />What is a session?<br />
  3. 3. Access the session object<br />Call request.getSession to get HttpSession object<br />This is a hashtable associated with the user<br />Look up information associated with a session.<br />Call getAttribute on the HttpSessionobject<br />Store information in a session.<br />Use setAttribute with a key and a value.<br />Discard session data.<br />Call removeAttribute discards a specific value.<br />Call invalidate to discard an entire session.<br />getID()<br />getAttributeNames()<br />Returns an Enumeration of String objects containing the names of all the objects bound to this session.<br />Session data<br />
  4. 4. Write a servlet A that stores 5 integers in session<br />Write a servlet B that echoes all the data in the session including the session id, and creation time<br />Excerise<br />
  5. 5. Some servers support distributed Web apps<br />Load balancing used to send different requests to different<br />machines. Sessions should still work even if different hosts are hit.<br />On some servers, you must call setAttribute to trigger replication<br />This is a tradeoff: session duplication can be expensive, but gives you better load balancing<br />Distributed and PersistentSessions<br />
  6. 6. Some servers support persistent sessions<br />Session data written to disk and reloaded when server is restarted (as long as browser stays open)<br />Tomcat 5 and 6 support this<br />User Serializable objects to store in distributed and persistent sessions.<br />Distributed and PersistentSessions<br />
  7. 7. Q&A<br />

×