Session Tracking Techniques
Session Tracking Techniques
Session Tracking…
• Session simply means a particular interval of time.
• Session Tracking is a way to maintain state (data) of
an user. It is also known as session management in
servlet.
• Http protocol is a stateless so we need to maintain
state using session tracking techniques. Each time
user requests to the server, server treats the
request as the new request. So we need to maintain
the state of an user to recognize to particular user.
Session Tracking…
• HTTP is stateless that means each request is
considered as the new request. It is shown in
the figure given below:
Why use Session Tracking?
• Constructor:
• Cookie() : constructs a cookie.
• Cookie(String name, String value): constructs a cookie
with a specified name and value.
• Methods
• public void setMaxAge(int expiry):Sets the maximum
age of the cookie in seconds.
• public String getName(): Returns the name of the
cookie. The name cannot be changed after creation.
• public String getValue(): Returns the value of the cookie.
• public void setName(String name): changes the name of
the cookie.
• public void setValue(String value): changes the value of
the cookie.
Methods…
• public void addCookie(Cookie ck):method of
HttpServletResponse interface is used to add
cookie in response object.
• public Cookie[] getCookies():method of
HttpServletRequest interface is used to return
all the cookies from the browser.
URL rewriting
• In URL rewriting, we append a token or
identifier to the URL of the next Servlet or the
next resource. We can send parameter
name/value pairs using the following format:
• url?name1=value1&name2=value2
• A name and a value is separated using an
equal = sign, a parameter name/value pair is
separated from another parameter using the
ampersand(&).
URL Rewriting…
Advantage of URL Rewriting
• It will always work whether cookie is disabled
or not (browser independent).
• Extra form submission is not required on each
pages.
Disadvantage of URL Rewriting
• It will work only with links.
• It can send Only textual information.
HttpSession