Ampli-Servlets Sesions - SERVLET SESSIONS Agenda...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
SERVLET SESSIONS
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Agenda Statelessness and Sessions Approach to Session Tracking HttpSession Interface Session LifeCycle State Management Servlet Context Servlet Collabration
Background image of page 2
Review We have discussed the Lifecycle of Servlets, API’s for requests and writing back the responses back to the clients. A servlet receives a request object, extracts the parameters if any from it ,processes application logic if any, and finally generates a response.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Review It may be possible that many clients can make multiple requests hence the server has to keep a track of requests and generate responses to specific clients. Hence the server is required to associate some form of uniqueness to each of the user. This is known as Session Tracking .
Background image of page 4
Statelessness and Session HTTP is a stateless protocol. A client opens a connection and request some resource. the server responds with every requested information or error status if not available. After closing the connection the server does not remember the client. So he considers the next request from the same client as a fresh request.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Statelessness and Session A protocol is stateful if the response to a given request may depend not only on the current request but also on the previous requests. It helps you to develop complex application logic across multiple requests and responses. For implementing this we need two facilities:- SESSION STATE
Background image of page 6
Statelessness and Session SESSION :- The server should be able to identify the series of request and responses from a single client form a single working ‘session’ STATE:- The server should be able to remember information related to previous requests and other business decisions that are made for requests.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
HTTP Vs Servlets HTTP It closes the connections at the end of every request. Hence http servers cannot use the notion of connections to establish a session. Http is a stateless protocol.
Background image of page 8
HTTP Vs Servlets Servlets The Java Servlet API provides facilities for tracking and to manage the state within a session. With the help of these facilities, the server can associate all of the requests together and know that they all came from the same user.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Approaches to Session Tracking There are four ways to track a session:- Cookies. Hidden form fields. URL rewriting. Sessions using Java Servlet API’s.
Background image of page 10
Cookies A cookie is a small piece of textual information sent by the server to the client, stored on the client, and returned by the client for all requests to server. A cookie contains one or more name-value pairs with certain additional attributes, which are exchanged in the response and request headers.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Cookies Web server send a cookie by sending the Set-Cookie response:- Set-Cookie : Name=value ;Comment=comment; Max- age=seconds; Path=path;Domain=domainname.
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

Ampli-Servlets Sesions - SERVLET SESSIONS Agenda...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online