SlideShare a Scribd company logo
1 of 10
Seminar Topic
Http Session
Prepared by- Mrittunjoy Das | MCA – Section (A)
ACHARYA INSTITUTE OF TECHNOLOGY
How to Use Sessions
• To use a session, first create a session using
the HttpServletRequest method getSession().
• Once the session is established, examine and set its properties
using the provided methods.
• If desired, set the session to time out after being inactive for a
defined time period, or invalidate it manually.
What we Look further ?
• Creating or Accessing a Session
• Examining Session Properties
• Binding Data to a Session
• Invalidating a Session
Creating or Accessing a Session
• To create a new session or gain access to an existing session,
use the HttpServletRequest method getSession()
• HttpSession mySession = request.getSession();
• getSession() - Returns the current session associated with this
request, or if the request does not have a session, creates one.
• getSession(boolean create) - Returns the current HttpSession
associated with this request or, if there is no current session
and arument passed is true then it returns a new session.
• false parameter to getSession() prevents the servlet from
creating a new session if one does not already exist.
Examining Session Properties
• Once a session ID has been established, use the methods in
the HttpSession interface to examine session properties, and
the methods in the HttpServletRequest interface to examine
request properties that relate to the session.
HttpSession Method Description
getCreationTime() Returns the session time in milliseconds since January 1,
1970, 00:00:00 GMT.
getId() Returns the assigned session identifier. An HTTP session's
identifier is a unique string that is created and maintained
by the server.
getLastAccessedTime() Returns the last time the client sent a request carrying the
assigned session identifier (or -1 if it’s a new session) in
milliseconds since January 1, 1970, 00:00:00 GMT.
isNew() Returns a Boolean value indicating if the session is new. It’s
a new session if the server has created it and the client has
not sent a request to it. This means the client has not
acknowledged or joined the session and may not return the
correct session identification information when making its
next request.
Contd…
HttpServletRequest Method Description
getRequestedSessionId() Returns the session ID specified with the request. This may
differ from the session ID in the current session if the session
ID given by the client is invalid and a new session was
created. Returns null if the request does not have a session
associated with it.
isRequestedSessionIdValid() Checks if the request is associated to a currently valid
session. If the session requested is not valid, it is not
returned through the getSession() method.
isRequestedSessionIdFromCookie() Returns true if the request's session ID provided by the client
is a cookie, or falseotherwise.
isRequestedSessionIdFromURL() Returns true if the request's session ID provided by the client
is a part of a URL, or false otherwise.
Binding Data to a Session
HttpSession Method Description
getAttribute() Returns the object bound to a given name in the session, or
null if there is no such binding.
getAttributeNames() Returns an array of names of all attributes bound to the
session.
setAttribute() Binds the specified object into the session with the given
name. Any existing binding with the same name is
overwritten. For an object bound into the session to be
distributed it must implement the serializable interface.
removeAttribute() Unbinds an object in the session with the given name. If
there is no object bound to the given name, this method
does nothing.
Invalidating a Session
• Direct the session to invalidate itself automatically after being
inactive for a defined time period.
• Alternatively, invalidate the session manually with
the HttpSession method invalidate().
Invalidating a Session Manually
• To invalidate a session manually, simply call the following
method:
• session.invalidate();
• All objects bound to the session are removed.
Setting a Session Timeout
In Web.xml Session Configuration
<session-config>
<session-timeout>30</session-timeout>
</session-config>
Reference
• https://docs.oracle.com/cd/E19857-01/819-
6518/gcxvp/index.html
• https://www.javatpoint.com/http-session-in-session-tracking
Thank You

More Related Content

What's hot

Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to SwaggerKnoldus Inc.
 
An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)Suman Guha
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP TutorialLorna Mitchell
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariSurekha Gadkari
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-AssuredMichel Schudel
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing SwaggerTony Tam
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGSiddharth Sharma
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & DevelopmentAshok Pundit
 
Angular data binding
Angular data binding Angular data binding
Angular data binding Sultan Ahmed
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaEdureka!
 
Developing Faster with Swagger
Developing Faster with SwaggerDeveloping Faster with Swagger
Developing Faster with SwaggerTony Tam
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)Brian Swartzfager
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
Accelerate Quality with Postman - Basics
Accelerate Quality with Postman - BasicsAccelerate Quality with Postman - Basics
Accelerate Quality with Postman - BasicsKnoldus Inc.
 

What's hot (20)

Angular
AngularAngular
Angular
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 
Async js
Async jsAsync js
Async js
 
Rest api-basic
Rest api-basicRest api-basic
Rest api-basic
 
An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)An introduction to Behavior-Driven Development (BDD)
An introduction to Behavior-Driven Development (BDD)
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-Assured
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing Swagger
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
 
BDD with Cucumber
BDD with CucumberBDD with Cucumber
BDD with Cucumber
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Angular data binding
Angular data binding Angular data binding
Angular data binding
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Developing Faster with Swagger
Developing Faster with SwaggerDeveloping Faster with Swagger
Developing Faster with Swagger
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Accelerate Quality with Postman - Basics
Accelerate Quality with Postman - BasicsAccelerate Quality with Postman - Basics
Accelerate Quality with Postman - Basics
 

Similar to Http session (Java) (20)

Advance java session 8
Advance java session 8Advance java session 8
Advance java session 8
 
Session Tracking in servlets
Session Tracking in servletsSession Tracking in servlets
Session Tracking in servlets
 
01 session tracking
01   session tracking01   session tracking
01 session tracking
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
 
Jsp session tracking
Jsp   session trackingJsp   session tracking
Jsp session tracking
 
Servlet
ServletServlet
Servlet
 
Ecom2
Ecom2Ecom2
Ecom2
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11
 
Lecture8
Lecture8Lecture8
Lecture8
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18
 
Servlet session 9
Servlet   session 9Servlet   session 9
Servlet session 9
 
J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environment
 
SERVIET
SERVIETSERVIET
SERVIET
 
self des session_T_M
self des session_T_Mself des session_T_M
self des session_T_M
 
Web Technologies -- Servlets 4 unit slides
Web Technologies -- Servlets   4 unit slidesWeb Technologies -- Servlets   4 unit slides
Web Technologies -- Servlets 4 unit slides
 
Servlets
ServletsServlets
Servlets
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Http session (Java)

  • 1. Seminar Topic Http Session Prepared by- Mrittunjoy Das | MCA – Section (A) ACHARYA INSTITUTE OF TECHNOLOGY
  • 2. How to Use Sessions • To use a session, first create a session using the HttpServletRequest method getSession(). • Once the session is established, examine and set its properties using the provided methods. • If desired, set the session to time out after being inactive for a defined time period, or invalidate it manually. What we Look further ? • Creating or Accessing a Session • Examining Session Properties • Binding Data to a Session • Invalidating a Session
  • 3. Creating or Accessing a Session • To create a new session or gain access to an existing session, use the HttpServletRequest method getSession() • HttpSession mySession = request.getSession(); • getSession() - Returns the current session associated with this request, or if the request does not have a session, creates one. • getSession(boolean create) - Returns the current HttpSession associated with this request or, if there is no current session and arument passed is true then it returns a new session. • false parameter to getSession() prevents the servlet from creating a new session if one does not already exist.
  • 4. Examining Session Properties • Once a session ID has been established, use the methods in the HttpSession interface to examine session properties, and the methods in the HttpServletRequest interface to examine request properties that relate to the session. HttpSession Method Description getCreationTime() Returns the session time in milliseconds since January 1, 1970, 00:00:00 GMT. getId() Returns the assigned session identifier. An HTTP session's identifier is a unique string that is created and maintained by the server. getLastAccessedTime() Returns the last time the client sent a request carrying the assigned session identifier (or -1 if it’s a new session) in milliseconds since January 1, 1970, 00:00:00 GMT. isNew() Returns a Boolean value indicating if the session is new. It’s a new session if the server has created it and the client has not sent a request to it. This means the client has not acknowledged or joined the session and may not return the correct session identification information when making its next request.
  • 5. Contd… HttpServletRequest Method Description getRequestedSessionId() Returns the session ID specified with the request. This may differ from the session ID in the current session if the session ID given by the client is invalid and a new session was created. Returns null if the request does not have a session associated with it. isRequestedSessionIdValid() Checks if the request is associated to a currently valid session. If the session requested is not valid, it is not returned through the getSession() method. isRequestedSessionIdFromCookie() Returns true if the request's session ID provided by the client is a cookie, or falseotherwise. isRequestedSessionIdFromURL() Returns true if the request's session ID provided by the client is a part of a URL, or false otherwise.
  • 6. Binding Data to a Session HttpSession Method Description getAttribute() Returns the object bound to a given name in the session, or null if there is no such binding. getAttributeNames() Returns an array of names of all attributes bound to the session. setAttribute() Binds the specified object into the session with the given name. Any existing binding with the same name is overwritten. For an object bound into the session to be distributed it must implement the serializable interface. removeAttribute() Unbinds an object in the session with the given name. If there is no object bound to the given name, this method does nothing.
  • 7. Invalidating a Session • Direct the session to invalidate itself automatically after being inactive for a defined time period. • Alternatively, invalidate the session manually with the HttpSession method invalidate(). Invalidating a Session Manually • To invalidate a session manually, simply call the following method: • session.invalidate(); • All objects bound to the session are removed.
  • 8. Setting a Session Timeout In Web.xml Session Configuration <session-config> <session-timeout>30</session-timeout> </session-config>