SlideShare a Scribd company logo
Java/J2ee Programming Training
Session
Page 2Classification: Restricted
Agenda
• HTTP Protocol
• HttpSession API
• Destroying the session of webapp
• Cookies
• Session Management using Cookie
• Url Rewriting
Page 3Classification: Restricted
Http Protocol
• Http is a stateless protocol
• Each request is considered as new request by the server
• Protocol does not remember the conversational state
NEW
NEW
NEW
NEW
same
user
Java Session
Page 7Classification: Restricted
HttpSession
• Identify the clients using HttpSession
• Information about client is stored in session object
req HttpSession
HttpSession session = request.getSession()
req
res
req
res
service
service
reqsession req.getSession()
HttpSession session = req.getSession();
reqsession req.getSession()
HttpSession session = req.getSession();
session.setAttribute(“home”,Home );
session.setAttribute(“home”,Home);
req
user=Tomsession req.getSession()
HttpSession session = req.getSession();
session.setAttribute(“user”,Tom);
session.setAttribute(“user”,Tom);
req
user=Tomsession req.getSession()
HttpSession session = req.getSession();
String user = (String)session.getAttribute(“user”);
session.getAttribute(“user”);
req
user=Tomsession req.getSession()
HttpSession session = req.getSession();
session.removeAttribute(“user”);
session.removeAttribute(“user”,Tom);
req
user=Tomsession req.getSession()
HttpSession session = req.getSession();
session.removeAttribute(“user”);
session.invalidate();
session.invalidate()
Page 18Classification: Restricted
HttpSession API
Page 19Classification: Restricted
Page 20Classification: Restricted
Destroying the session of webapp
user/pwd in invalid
${requestScope.error}
submit
class LoginServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
if( user.equals(“tom”) && pwd.equals(“hr”))
{
HttpSession session = request.getSession(true);
session.setAttribute(“username”, user);
response.sendRedirect(“Home.jsp”);
}
else
{
RequestDispatcher rd=
request.getRequestDispatcher(“Login.jsp”);
request.setAttribute(“error”, “user/pwd is invalid”);
rd.forward( request, response );
}
}
}
Hi John,
${sessionScope.user}
Home About
session user=tom
Home.jsp
user/pwd in invalid
${requestScope.error}
submit
class LogoutServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
HttpSession session = request.getSession(false);
session.removeAttribute(“username”);
session.invalidate();
}
}
Hi John,
${sessionScope.user}
Home About
session user=tom
Home.jsp
Page 23Classification: Restricted
HttpSession
• Is accessible to all the web components through out the session.
response.sendRedirect() Vs rd.forward(req, res);
rd.foward(req,res)
response.sendRedirect();
Page 25Classification: Restricted
Cookies
• Cookies allow webserver to store information
on client machine
• cookies are sent in response from web server
• cookies are stored in partition assigned to webserver domain
• All cookies for the webserver are sent on every request to the webserver
Page 26Classification: Restricted
Cookies
• cookies have a lifespan and are flushed by the browser at the end of
lifespan
-cookies are flushed when the browser exits, if the lifespan is not
configured
Page 27Classification: Restricted
Cookie API
Session Management using Cookie
Page 29Classification: Restricted
Session Management using Cookie
Page 30Classification: Restricted
Session Management using Cookie
• Storing Cookie • Retrieving Cooking
Page 31Classification: Restricted
Typical Uses of Cookies
• – Identifying a user during an e-commerce session
• – Avoiding username and password
• – Focusing advertising
• – Customizing a site
Remember Me
submit
if ( rememberMe)
{
Cookie c = new Cookie(“user”, username);
response.addCookie( c ) ;
Cookie c2 = new Cookie(“pass”, pass);
response.addCookie( c2 )
}
user=tom
pass=tom
Remember Me
submit
if ( rememberMe)
{
Cookie c = new Cookie(“user”, username);
response.addCookie( c ) ;
Cookie c2 = new Cookie(“pass”, pass);
response.addCookie( c2 )
}
user=tom
pass=tom
Remember Me
submit
Cookies cookies[] =request.getCookies();
out.println( c[ 0 ].getName() + “ = “ + c[ 0].getValue());
out.println( c[ 1 ].getName() + “ = “ + c[ 1 ].getValue());
request
user=tom
pass=tom
0 1
user=tom pass=tom
Page 35Classification: Restricted
Url Rewriting
String url = response.encodeURL(“fact.do”);
Page 36Classification: Restricted
Thank You

More Related Content

What's hot (20)

PDF
FME Cloud Goes Blockchain - Accepting Payments via Bitcoins with FME Server
Safe Software
 
PPTX
Token Based Authentication Systems
Hüseyin BABAL
 
PDF
Autenticação com Json Web Token (JWT)
Ivan Rosolen
 
PDF
JSON Web Tokens
Ivan Rosolen
 
PDF
JSON Web Token
Deddy Setyadi
 
PDF
Java and the blockchain - introducing web3j
Conor Svensson
 
PPTX
Advance java session 7
Smita B Kumar
 
PPTX
Session tracking In Java
honeyvachharajani
 
PDF
Introduction to php web programming - sessions and cookies
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Cookie and session
Aashish Ghale
 
PDF
ZServer Reloaded with HTTP/2 and WebSocket Support
Asko Soukka
 
PPTX
Web fundamentals - part 1
Bozhidar Boshnakov
 
PPTX
Overview of Cookies in HTTP - Miran al Mehrab
Cefalo
 
PPTX
Synchronous communication using jms back channel
sivachandra mandalapu
 
DOCX
jQuery Code Testing
Elizabeth Pisarek
 
PDF
.htaccess Cheatsheet
Shankar Soma
 
PDF
Php & web server performace
Tuyển Đoàn
 
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
PDF
Presentatie 3Fifty: TOPdesk-MS SCOM-koppeling
TOPdesk
 
PPTX
Token Based Authentication Systems with AngularJS & NodeJS
Hüseyin BABAL
 
FME Cloud Goes Blockchain - Accepting Payments via Bitcoins with FME Server
Safe Software
 
Token Based Authentication Systems
Hüseyin BABAL
 
Autenticação com Json Web Token (JWT)
Ivan Rosolen
 
JSON Web Tokens
Ivan Rosolen
 
JSON Web Token
Deddy Setyadi
 
Java and the blockchain - introducing web3j
Conor Svensson
 
Advance java session 7
Smita B Kumar
 
Session tracking In Java
honeyvachharajani
 
Introduction to php web programming - sessions and cookies
baabtra.com - No. 1 supplier of quality freshers
 
Cookie and session
Aashish Ghale
 
ZServer Reloaded with HTTP/2 and WebSocket Support
Asko Soukka
 
Web fundamentals - part 1
Bozhidar Boshnakov
 
Overview of Cookies in HTTP - Miran al Mehrab
Cefalo
 
Synchronous communication using jms back channel
sivachandra mandalapu
 
jQuery Code Testing
Elizabeth Pisarek
 
.htaccess Cheatsheet
Shankar Soma
 
Php & web server performace
Tuyển Đoàn
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
Presentatie 3Fifty: TOPdesk-MS SCOM-koppeling
TOPdesk
 
Token Based Authentication Systems with AngularJS & NodeJS
Hüseyin BABAL
 

Similar to Java Session (20)

PPTX
Session 32 - Session Management using Cookies
PawanMM
 
PPTX
Session 33 - Session Management using other Techniques
PawanMM
 
PPT
Generating the Server Response: HTTP Status Codes
DeeptiJava
 
PPTX
WORKING WITH IN COOKIES JAVA SEMINAR.pptx
nandhini342004
 
PPTX
Working with in cookies java seminar.pptx
nandhini342004
 
PPTX
Using cookies and sessions
Nuha Noor
 
PPTX
SessionTrackServlets.pptx
Ranjeet Reddy
 
PPTX
19_JavaScript - Storage_Cookies-tutorial .pptx
ssuser4a97d3
 
PDF
07 cookies
snopteck
 
PPT
Ecom2
Santosh Pandey
 
PDF
OWASP AppSec USA 2017: Cookie Security – Myths and Misconceptions by David Jo...
David Johansson
 
PPT
Session and cookies,get and post methods
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
yvtinsane
 
PDF
Servlet sessions
vantinhkhuc
 
PPTX
Session And Cookies In Servlets - Java
JainamParikh3
 
PPTX
Java Rest
AathikaJava
 
PPTX
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
PawanMM
 
PPT
Synapse india dotnet development web approch part 2
Synapseindiappsdevelopment
 
PPTX
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
PPTX
Session tracking in servlets
vishal choudhary
 
Session 32 - Session Management using Cookies
PawanMM
 
Session 33 - Session Management using other Techniques
PawanMM
 
Generating the Server Response: HTTP Status Codes
DeeptiJava
 
WORKING WITH IN COOKIES JAVA SEMINAR.pptx
nandhini342004
 
Working with in cookies java seminar.pptx
nandhini342004
 
Using cookies and sessions
Nuha Noor
 
SessionTrackServlets.pptx
Ranjeet Reddy
 
19_JavaScript - Storage_Cookies-tutorial .pptx
ssuser4a97d3
 
07 cookies
snopteck
 
OWASP AppSec USA 2017: Cookie Security – Myths and Misconceptions by David Jo...
David Johansson
 
Session and cookies,get and post methods
baabtra.com - No. 1 supplier of quality freshers
 
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
yvtinsane
 
Servlet sessions
vantinhkhuc
 
Session And Cookies In Servlets - Java
JainamParikh3
 
Java Rest
AathikaJava
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
PawanMM
 
Synapse india dotnet development web approch part 2
Synapseindiappsdevelopment
 
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
Session tracking in servlets
vishal choudhary
 
Ad

More from AathikaJava (16)

PPTX
Java While Loop
AathikaJava
 
PPTX
Java Webservices
AathikaJava
 
PPTX
Java Type Casting
AathikaJava
 
PPTX
Spring Web MVC
AathikaJava
 
PPTX
Java Servlet Lifecycle
AathikaJava
 
PPTX
Java Request Dispatcher
AathikaJava
 
PPTX
Java Polymorphism Part 2
AathikaJava
 
PPTX
Java MVC
AathikaJava
 
PPTX
Java Polymorphism
AathikaJava
 
PPTX
Java Spring
AathikaJava
 
PPTX
Mapping Classes with Relational Databases
AathikaJava
 
PPTX
Introduction to Java
AathikaJava
 
PPTX
Java Encapsulation and Inheritance
AathikaJava
 
PPT
Hibernate basics
AathikaJava
 
PPTX
Java Filters
AathikaJava
 
PPTX
Encapsulation
AathikaJava
 
Java While Loop
AathikaJava
 
Java Webservices
AathikaJava
 
Java Type Casting
AathikaJava
 
Spring Web MVC
AathikaJava
 
Java Servlet Lifecycle
AathikaJava
 
Java Request Dispatcher
AathikaJava
 
Java Polymorphism Part 2
AathikaJava
 
Java MVC
AathikaJava
 
Java Polymorphism
AathikaJava
 
Java Spring
AathikaJava
 
Mapping Classes with Relational Databases
AathikaJava
 
Introduction to Java
AathikaJava
 
Java Encapsulation and Inheritance
AathikaJava
 
Hibernate basics
AathikaJava
 
Java Filters
AathikaJava
 
Encapsulation
AathikaJava
 
Ad

Recently uploaded (20)

PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
July Patch Tuesday
Ivanti
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
July Patch Tuesday
Ivanti
 

Java Session