SlideShare a Scribd company logo
SESSION
TRACKING
HoneyGurnaniM.EComputer
Prof Honey Gurnani
I/C Computer Department
Tolani FG Polytechnic
WHAT IS SESSION
 Session simply means a particular interval of time.
 A series of related interactions between a single client
and web server over a period of time.
WHAT IS SESSION TRACKING
 A way to maintain state (data) of an user. It is also
known as session management in servlet.
 Tracking data among request in a session.
HoneyGurnaniM.EComputer
HTTP PROTOCOL & SESSION TRACKING
 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.
 In many cases, information has to be saved for the
future purpose or for some reference.
 Session provides such mechanism
HoneyGurnaniM.EComputer
HoneyGurnaniM.EComputer
SESSION TRACKING TECHNIQUES
There are four techniques used in Session tracking:
 HttpSession
 Cookies
 Hidden Form Field
 URL Rewriting
HoneyGurnaniM.EComputer
MAINTAINING SESSION THROUGH SESSION
TRACKING API -: HTTPSESSION INTERFACE
 In such case, container creates a session id for
each user.
 The container uses this id to identify the particular
user.
 An object of HttpSession can be used to perform
two tasks:
1. bind objects
2. view and manipulate information about a session,
such as the session identifier, creation time, and
last accessed time.
HoneyGurnaniM.EComputer
HoneyGurnaniM.EComputer
HOW TO GET THE HTTPSESSION OBJECT ?
 public HttpSession getSession():Returns the
current session associated with this request, or if
the request does not have a session, creates one.
 public HttpSession getSession(boolean
create):Returns the current HttpSession associated
with this request or, if there is no current session
and create is true, returns a new session.
HoneyGurnaniM.EComputer
METHODS OF HTTPSESSION INTERFACE
 public String getId():Returns a string containing
the unique identifier value.
 public long getCreationTime():Returns the time
when this session was created, measured in
milliseconds since midnight January 1, 1970 GMT.
 public long getLastAccessedTime():Returns the
last time the client sent a request associated with
this session, as the number of milliseconds since
midnight January 1, 1970 GMT.
 public void invalidate():Invalidates this session
then unbinds any objects bound to it.
HoneyGurnaniM.EComputer
ADVANTAGES OF HTTP SESSIONS IN
SERVLET
 Any kind of object can be stored into a session, be
it a text, database, dataset etc.
 Usage of sessions is not dependent on the client’s
browser.
 Sessions are secure and transparent
HoneyGurnaniM.EComputer
MAINTAINING SESSION THROUGH COOKIES
 A cookie is a small piece of information that is
persisted between the multiple client requests.
 A cookie has a name, a single value, and optional
attributes such as a comment, path and domain
qualifiers, a maximum age, and a version number.
HoneyGurnaniM.EComputer
WORKING OF COOKIE
 By default, each request is considered as a new
request.
 In cookies technique, we add cookie with response
from the servlet.
 So cookie is stored in the cache of the browser.
 After that if request is sent by the user, cookie is
added with request by default.
 Thus, we recognize the user as the old user.
HoneyGurnaniM.EComputer
TYPES OF COOKIES
 There are 2 types of cookies in servlets.
Non-persistent cookie
Persistent cookie
 Non-persistent cookie
It is valid for single session only. It is removed each
time when user closes the browser.
 Persistent cookie
It is valid for multiple session . It is not removed
each time when user closes the browser. It is
removed only if user logout or signout.
HoneyGurnaniM.EComputer
ADVANTAGE OF COOKIES
 Simplest technique of maintaining the state.
 Cookies are maintained at client side.
HoneyGurnaniM.EComputer
DISADVANTAGE OF COOKIES
 It will not work if cookie is disabled from the
browser.
 Only textual information can be set in Cookie
object.
HoneyGurnaniM.EComputer
HoneyGurnaniM.EComputer
COOKIE CLASS
 javax.servlet.http.Cookie class provides the
functionality of using cookies. It provides a lot of
useful methods for cookies.
 Cookie Constructor
Constructor Description
Cookie() Constructs a cookie.
Cookie(String name, String value) Constructs a cookie with a specified
name and value.
HoneyGurnaniM.EComputer
METHODS OF COOKIES
Method Description
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.
HoneyGurnaniM.EComputer
HIDDEN FIELD
 A hidden (invisible) textfield is used for
maintaining the state of an user.
 Store the information in the hidden field and get it
from another servlet.
 This approach is better if we have to submit form in
all the pages and we don't want to depend on the
browser.
HoneyGurnaniM.EComputer
REAL APPLICATION OF HIDDEN FORM FIELD
 It is widely used in comment form of a website. In
such case, we store page id or page name in the
hidden field so that each page can be uniquely
identified.
HoneyGurnaniM.EComputer
HoneyGurnaniM.EComputer
ADVANTAGE OF HIDDEN FORM FIELD
 It will always work whether cookie is disabled or
not.
HoneyGurnaniM.EComputer
DISADVANTAGE OF HIDDEN FORM FIELD:
 It is maintained at server side.
 Extra form submission is required on each pages.
 Only textual information can be used.
HoneyGurnaniM.EComputer
URL REWRITING
 In URL rewriting, we append a token or identifier to
the URL of the next Servlet or the next resource.
 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(&).
 When the user clicks the hyperlink, the parameter
name/value pairs will be passed to the server.
 From a Servlet, we can use getParameter() method
to obtain a parameter value.
HoneyGurnaniM.EComputer
HoneyGurnaniM.EComputer
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.
HoneyGurnaniM.EComputer
DISADVANTAGE OF URL REWRITING
 It will work only with links.
 It can send Only textual information.
HoneyGurnaniM.EComputer
THANKYOU
HoneyGurnaniM.EComputer

More Related Content

What's hot (20)

PPTX
Event In JavaScript
ShahDhruv21
 
PPS
Java rmi
kamal kotecha
 
PPT
Java Networking
Sunil OS
 
PPT
Servlet life cycle
Venkateswara Rao N
 
PPT
Java Servlets
BG Java EE Course
 
PPT
16. Concurrency Control in DBMS
koolkampus
 
PDF
Agreement Protocols, distributed File Systems, Distributed Shared Memory
SHIKHA GAUTAM
 
PPTX
jstl ( jsp standard tag library )
Adarsh Patel
 
PDF
Remote Method Invocation (RMI)
Peter R. Egli
 
PPTX
Servlets
ZainabNoorGul
 
PPTX
Http session (Java)
Mrittunjoy Das
 
PPTX
String matching algorithms
Ashikapokiya12345
 
PPTX
Socket programming in Java (PPTX)
UC San Diego
 
PPTX
HTTP request and response
Sahil Agarwal
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PPSX
Introduction to Html5
www.netgains.org
 
PPTX
Android activity lifecycle
Soham Patel
 
PPT
Awt controls ppt
soumyaharitha
 
Event In JavaScript
ShahDhruv21
 
Java rmi
kamal kotecha
 
Java Networking
Sunil OS
 
Servlet life cycle
Venkateswara Rao N
 
Java Servlets
BG Java EE Course
 
16. Concurrency Control in DBMS
koolkampus
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
SHIKHA GAUTAM
 
jstl ( jsp standard tag library )
Adarsh Patel
 
Remote Method Invocation (RMI)
Peter R. Egli
 
Servlets
ZainabNoorGul
 
Http session (Java)
Mrittunjoy Das
 
String matching algorithms
Ashikapokiya12345
 
Socket programming in Java (PPTX)
UC San Diego
 
HTTP request and response
Sahil Agarwal
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Introduction to Html5
www.netgains.org
 
Android activity lifecycle
Soham Patel
 
Awt controls ppt
soumyaharitha
 

Similar to Session tracking In Java (20)

PPTX
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
yvtinsane
 
PPTX
SessionTrackServlets.pptx
Ranjeet Reddy
 
PPTX
Session tracking in servlets
vishal choudhary
 
PPTX
Using cookies and sessions
Nuha Noor
 
PPTX
Enterprise java unit-2_chapter-3
sandeep54552
 
PPT
Ecom2
Santosh Pandey
 
PDF
Servlet sessions
vantinhkhuc
 
PPTX
Session And Cookies In Servlets - Java
JainamParikh3
 
PPTX
Servlet session 10
Anuj Singh Rajput
 
PPTX
SCWCD : Session management : CHAP : 6
Ben Abdallah Helmi
 
PPTX
Enterprise java unit-2_chapter-2
sandeep54552
 
PPTX
Session 33 - Session Management using other Techniques
PawanMM
 
PPTX
Session 32 - Session Management using Cookies
PawanMM
 
PPTX
COOKIES.pptx
18csjeyavarthini
 
PPT
Cookies in servlet
chauhankapil
 
PPTX
Advance java session 7
Smita B Kumar
 
PPT
session and cookies.ppt
Jayaprasanna4
 
PPTX
Class 38
srasat73
 
PDF
4.4 PHP Session
Jalpesh Vasa
 
PPTX
Advance java session 8
Smita B Kumar
 
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
yvtinsane
 
SessionTrackServlets.pptx
Ranjeet Reddy
 
Session tracking in servlets
vishal choudhary
 
Using cookies and sessions
Nuha Noor
 
Enterprise java unit-2_chapter-3
sandeep54552
 
Servlet sessions
vantinhkhuc
 
Session And Cookies In Servlets - Java
JainamParikh3
 
Servlet session 10
Anuj Singh Rajput
 
SCWCD : Session management : CHAP : 6
Ben Abdallah Helmi
 
Enterprise java unit-2_chapter-2
sandeep54552
 
Session 33 - Session Management using other Techniques
PawanMM
 
Session 32 - Session Management using Cookies
PawanMM
 
COOKIES.pptx
18csjeyavarthini
 
Cookies in servlet
chauhankapil
 
Advance java session 7
Smita B Kumar
 
session and cookies.ppt
Jayaprasanna4
 
Class 38
srasat73
 
4.4 PHP Session
Jalpesh Vasa
 
Advance java session 8
Smita B Kumar
 
Ad

Recently uploaded (20)

PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Dimensions of Societal Planning in Commonism
StefanMz
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Ad

Session tracking In Java

  • 1. SESSION TRACKING HoneyGurnaniM.EComputer Prof Honey Gurnani I/C Computer Department Tolani FG Polytechnic
  • 2. WHAT IS SESSION  Session simply means a particular interval of time.  A series of related interactions between a single client and web server over a period of time. WHAT IS SESSION TRACKING  A way to maintain state (data) of an user. It is also known as session management in servlet.  Tracking data among request in a session. HoneyGurnaniM.EComputer
  • 3. HTTP PROTOCOL & SESSION TRACKING  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.  In many cases, information has to be saved for the future purpose or for some reference.  Session provides such mechanism HoneyGurnaniM.EComputer
  • 5. SESSION TRACKING TECHNIQUES There are four techniques used in Session tracking:  HttpSession  Cookies  Hidden Form Field  URL Rewriting HoneyGurnaniM.EComputer
  • 6. MAINTAINING SESSION THROUGH SESSION TRACKING API -: HTTPSESSION INTERFACE  In such case, container creates a session id for each user.  The container uses this id to identify the particular user.  An object of HttpSession can be used to perform two tasks: 1. bind objects 2. view and manipulate information about a session, such as the session identifier, creation time, and last accessed time. HoneyGurnaniM.EComputer
  • 8. HOW TO GET THE HTTPSESSION OBJECT ?  public HttpSession getSession():Returns the current session associated with this request, or if the request does not have a session, creates one.  public HttpSession getSession(boolean create):Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session. HoneyGurnaniM.EComputer
  • 9. METHODS OF HTTPSESSION INTERFACE  public String getId():Returns a string containing the unique identifier value.  public long getCreationTime():Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.  public long getLastAccessedTime():Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.  public void invalidate():Invalidates this session then unbinds any objects bound to it. HoneyGurnaniM.EComputer
  • 10. ADVANTAGES OF HTTP SESSIONS IN SERVLET  Any kind of object can be stored into a session, be it a text, database, dataset etc.  Usage of sessions is not dependent on the client’s browser.  Sessions are secure and transparent HoneyGurnaniM.EComputer
  • 11. MAINTAINING SESSION THROUGH COOKIES  A cookie is a small piece of information that is persisted between the multiple client requests.  A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. HoneyGurnaniM.EComputer
  • 12. WORKING OF COOKIE  By default, each request is considered as a new request.  In cookies technique, we add cookie with response from the servlet.  So cookie is stored in the cache of the browser.  After that if request is sent by the user, cookie is added with request by default.  Thus, we recognize the user as the old user. HoneyGurnaniM.EComputer
  • 13. TYPES OF COOKIES  There are 2 types of cookies in servlets. Non-persistent cookie Persistent cookie  Non-persistent cookie It is valid for single session only. It is removed each time when user closes the browser.  Persistent cookie It is valid for multiple session . It is not removed each time when user closes the browser. It is removed only if user logout or signout. HoneyGurnaniM.EComputer
  • 14. ADVANTAGE OF COOKIES  Simplest technique of maintaining the state.  Cookies are maintained at client side. HoneyGurnaniM.EComputer
  • 15. DISADVANTAGE OF COOKIES  It will not work if cookie is disabled from the browser.  Only textual information can be set in Cookie object. HoneyGurnaniM.EComputer
  • 17. COOKIE CLASS  javax.servlet.http.Cookie class provides the functionality of using cookies. It provides a lot of useful methods for cookies.  Cookie Constructor Constructor Description Cookie() Constructs a cookie. Cookie(String name, String value) Constructs a cookie with a specified name and value. HoneyGurnaniM.EComputer
  • 18. METHODS OF COOKIES Method Description 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. HoneyGurnaniM.EComputer
  • 19. HIDDEN FIELD  A hidden (invisible) textfield is used for maintaining the state of an user.  Store the information in the hidden field and get it from another servlet.  This approach is better if we have to submit form in all the pages and we don't want to depend on the browser. HoneyGurnaniM.EComputer
  • 20. REAL APPLICATION OF HIDDEN FORM FIELD  It is widely used in comment form of a website. In such case, we store page id or page name in the hidden field so that each page can be uniquely identified. HoneyGurnaniM.EComputer
  • 22. ADVANTAGE OF HIDDEN FORM FIELD  It will always work whether cookie is disabled or not. HoneyGurnaniM.EComputer
  • 23. DISADVANTAGE OF HIDDEN FORM FIELD:  It is maintained at server side.  Extra form submission is required on each pages.  Only textual information can be used. HoneyGurnaniM.EComputer
  • 24. URL REWRITING  In URL rewriting, we append a token or identifier to the URL of the next Servlet or the next resource.  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(&).  When the user clicks the hyperlink, the parameter name/value pairs will be passed to the server.  From a Servlet, we can use getParameter() method to obtain a parameter value. HoneyGurnaniM.EComputer
  • 26. 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. HoneyGurnaniM.EComputer
  • 27. DISADVANTAGE OF URL REWRITING  It will work only with links.  It can send Only textual information. HoneyGurnaniM.EComputer