Download presentation
Presentation is loading. Please wait.
Published byRonald Rice Modified over 6 years ago
1
Sessions Many interactive Web sites spread user data entry out over several pages: Ex: add items to cart, enter shipping information, enter billing information Problem: how does the server know which users generated which HTTP requests? Cannot rely on standard HTTP headers to identify a user
2
Sessions
3
Sessions Server sends back new unique session ID when the request has
none
4
Sessions Client that supports session stores the ID and sends it
back to the server in subsequent requests
5
Sessions Server knows that all of these requests are from the same
client. The set of requests is known as a session.
6
Sessions And the server knows that all of these requests are
from a different client.
7
Session Tracking It is a concept which allows you to maintain a relation between 2 successive requests made to a server on the internet. HTTP Stateless protocol Implement the session tracking Http session object live on server which seems like hash table - Hidden fields in form <input type=“hidden” name=“bookID” value=“100”> - URL Rewriting hidden fields are view some browser specify the limit on the length of the URL Example search result for book with checkbox <b>Search results for books</b> <form method =“post” action =“serverprogram.jsp”> <input type=“checkbox” name=“bookID” value=“100”> Java Servlet Programming <br> <input type=“checkbox” name=“bookID” value=“101”> C Programming <br> </form>
8
Basic steps for session tracking
Accessing the session object associated with the current request Call request.getSession() to get an HttpSession object which is a simple hash table for storing user-specific data. Looking up information associated with a session. Call getAttribute() on the HttpSession object, cast the return value to the appropriate type,and check whether the result is null. Storing information in a session. Use setAttribute() wth a key and a value. Discarding session data. Call removeAttribute() to discard a specific value. Call invalidate() to discard an entire session Method of getId() Returns the unique identifier generated for each session. Method of isNew() Returns true : if the client (browser) has never seen the session Returns false: for preexisting session.
9
Sessions Returns HttpSession object associated with this HTTP request.
Creates new HttpSession object if no session ID in request or no object with this ID exists Otherwise, returns previously created object
10
Sessions Boolean indicating whether returned
object was newly created or already existed.
11
Sessions Incremented once per session
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.