SlideShare a Scribd company logo
7/23/2017 JSP - Session Tracking
https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 1/5
Classic Codes & Dashing Developer (Ashok Kumar Pachauri) originated from the idea that there exists a class of
readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of
their drawing rooms. we are working our way to adding fresh tutorials to our repository which now proudly aunts a
wealth of tutorials and allied articles on topics ranging from programming languages to web designing to
academics and much more.
JSP - Session Tracking
July 22, 2017
In this chapter, we will discuss session tracking in JSP. HTTP is a "stateless" protocol which means each
time a client retrieves a Webpage, the client opens a separate connection to the Web server and the
server automatically does not keep any record of previous client request.
Let us now discuss a few options to maintain the session between the Web Client and the Web Server −
A webserver can assign a unique session ID as a cookie to each web client and for subsequent requests
from the client they can be recognized using the received cookie.
This may not be an effective way as the browser at times does not support a cookie. It is not
recommended to use this procedure to maintain the sessions.
A web server can send a hidden HTML form field along with a unique session ID as follows −
<input type = "hidden" name = "sessionid" value = "12345">
This entry means that, when the form is submitted, the specified name and value are automatically
included in the GET or the POST data. Each time the web browser sends the request back,
the session_id value can be used to keep the track of different web browsers.
This can be an effective way of keeping track of the session but clicking on a regular (<A HREF...>)
hypertext link does not result in a form submission, so hidden form fields also cannot support general
session tracking.
You can append some extra data at the end of each URL. This data identifies the session; the server can
associate that session identifier with the data it has stored about that session.
For example, with http://tutorialspoint.com/file.htm;sessionid=12345, the session identifier is
attached as sessionid = 12345 which can be accessed at the web server to identify the client.
URL rewriting is a better way to maintain sessions and works for the browsers when they don't support
cookies. The drawback here is that you will have to generate every URL dynamically to assign a session
ID though page is a simple static HTML page.
Apart from the above mentioned options, JSP makes use of the servlet provided HttpSession Interface.
This interface provides a way to identify a user across.
a one page request or
visit to a website or
store information about that user
By default, JSPs have session tracking enabled and a new HttpSession object is instantiated for each new
client automatically. Disabling session tracking requires explicitly turning it off by setting the page
directive session attribute to false as follows −
<%@ page session = "false" %>
The JSP engine exposes the HttpSession object to the JSP author through the implicit session object.
Since session object is already provided to the JSP programmer, the programmer can immediately begin
storing and retrieving data from the object without any initialization or getSession().
Here is a summary of important methods available through the session object −
S.No. Method & Description
1
public Object getAttribute(String name)
This method returns the object bound with the specified name in
this session, or null if no object is bound under the name.
2 public Enumeration getAttributeNames()
This method returns an Enumeration of String objects containing
the names of all the objects bound to this session.
3
public long getCreationTime()
This method returns the time when this session was created,
measured in milliseconds since midnight January 1, 1970 GMT.
public String getId()
Maintaining Session Between Web Client And Server
Cookies
Hidden Form Fields
URL Rewriting
The session Object
7/23/2017 JSP - Session Tracking
https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 2/5
4
public String getId()
This method returns a string containing the unique identifier
assigned to this session.
5
public long getLastAccessedTime()
This method returns the last time the client sent a request
associated with the this session, as the number of milliseconds
since midnight January 1, 1970 GMT.
6
public int getMaxInactiveInterval()
This method returns the maximum time interval, in seconds, that
the servlet container will keep this session open between client
accesses.
7
public void invalidate()
This method invalidates this session and unbinds any objects bound
to it.
8
public boolean isNew()
This method returns true if the client does not yet know about the
session or if the client chooses not to join the session.
9
public void removeAttribute(String name)
This method removes the object bound with the specified name
from this session.
10
public void setAttribute(String name, Object value)
This method binds an object to this session, using the name
specified.
11
public void setMaxInactiveInterval(int interval)
This method specifies the time, in seconds, between client requests
before the servlet container will invalidate this session.
This example describes how to use the HttpSession object to find out the creation time and the last-
accessed time for a session. We would associate a new session with the request if one does not already
exist.
<%@ page import = "java.io.*,java.util.*" %>
<%
// Get session creation time.
Date createTime = new Date(session.getCreationTime());
// Get last access time of this Webpage.
Date lastAccessTime = new Date(session.getLastAccessedTime());
String title = "Welcome Back to my website";
Integer visitCount = new Integer(0);
String visitCountKey = new String("visitCount");
String userIDKey = new String("userID");
String userID = new String("ABCD");
// Check if this is new comer on your Webpage.
if (session.isNew() ){
title = "Welcome to my website";
session.setAttribute(userIDKey, userID);
session.setAttribute(visitCountKey, visitCount);
}
visitCount = (Integer)session.getAttribute(visitCountKey);
visitCount = visitCount + 1;
userID = (String)session.getAttribute(userIDKey);
session.setAttribute(visitCountKey, visitCount);
%>
<html>
<head>
<title>Session Tracking</title>
</head>
<body>
<center>
<h1>Session Tracking</h1>
</center>
<table border = "1" align = "center">
<tr bgcolor = "#949494">
<th>Session info</th>
<th>Value</th>
</tr>
<tr>
<td>id</td>
<td><% out.print( session.getId()); %></td>
</tr>
<tr>
<td>Creation Time</td>
<td><% out.print(createTime); %></td>
</tr>
<tr>
<td>Time of Last Access</td>
<td><% out.print(lastAccessTime); %></td>
</tr>
<tr>
<td>User ID</td>
<td><% out.print(userID); %></td>
</tr>
<tr>
<td>Number of visits</td>
<td><% out.print(visitCount); %></td>
</tr>
</table>
</body>
</html>
Now put the above code in main.jsp and try to access http://localhost:8080/main.jsp. Once you run
the URL, you will receive the following result −
Session Information
Session info value
id 0AE3EC93FF44E3C525B4351B77ABB2D5
Creation Time Tue Jun 08 17:26:40 GMT+04:00 2010
Time of Last Access Tue Jun 08 17:26:40 GMT+04:00 2010
User ID ABCD
Session Tracking Example
Welcome to my website
7/23/2017 JSP - Session Tracking
https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 3/5
JSP - Internationalization| i18n| l10n
JSP - Handling Date
JSP - Standard Tag Library (JSTL) Tutorial
No comments yet
Add a comment as Ashok kumar Pachauri (Dashing Developer)
Popular posts from this blog
July 22, 2017
July 22, 2017
July 22, 2017
User ID ABCD
Number of visits 0
Now try to run the same JSP for the second time, you will receive the following result.
Session Information
info type value
id 0AE3EC93FF44E3C525B4351B77ABB2D5
Creation Time Tue Jun 08 17:26:40 GMT+04:00 2010
Time of Last Access Tue Jun 08 17:26:40 GMT+04:00 2010
User ID ABCD
Number of visits 1
When you are done with a user's session data, you have several options −
Remove a particular attribute − You can call the public void removeAttribute(String
name) method to delete the value associated with the a particular key.
Delete the whole session − You can call the public void invalidate() method to discard an
entire session.
Setting Session timeout − You can call the public void setMaxInactiveInterval(int
interval) method to set the timeout for a session individually.
Log the user out − The servers that support servlets 2.4, you can call logout to log the client
out of the Web server and invalidate all sessions belonging to all the users.
web.xml Configuration − If you are using Tomcat, apart from the above mentioned methods,
you can configure the session time out in web.xml file as follows.
<session-config>
<session-timeout>15</session-timeout>
</session-config>
The timeout is expressed as minutes, and overrides the default timeout which is 30 minutes in Tomcat.
The getMaxInactiveInterval( ) method in a servlet returns the timeout period for that session in
seconds. So if your session is configured in web.xml for 15 minutes, getMaxInactiveInterval( ) returns
900.
Welcome Back to my website
Deleting Session Data
In this chapter, we will discuss the concept of Internationalization in JSP. Before we proceed, let us understand the
following three important terms − Internationalization (i18n) − This means enabling a website to provide different versions
of content translated into the visitor's language or nationality. Localization (l10n) − This means adding resources to a …
READ MORE
In this chapter, we will discuss how to handle data in JSP. One of the most important advantages of using JSP is that you
can use all the methods available in core Java. We will take you through the Date class which is available in
the java.util package; this class encapsulates the current date and time. The Date class supports two constructors. The …
READ MORE
In this chapter, we will understand the different tags in JSP. The JavaServer Pages Standard Tag Library (JSTL) is a
collection of useful JSP tags which encapsulates the core functionality common to many JSP applications. JSTL has
support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, …
READ MORE
7/23/2017 JSP - Session Tracking
https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 4/5
Translate
Select Language ▼
Following 9
Pages
Home
Introduction To JSP
JSP ENVIRONMENT SETUP
JSP ARCHITECTURE
JSP Life Cycle
JSP SYNTAX
JSP Directives
JSP ACTIONS
JSP - Implicit Objects
JSP - Client Request
JSP - Server Response
JSP - Http Status Codes
JSP - Form Processing
JSP - Filters
JSP - Cookies Handling
JSP - Session Tracking
JSP - File Uploading
JSP - Handling Date
JSP - Page Redirecting
JSP - Hits Counter
JSP - Auto Refresh
ASHOK KUMAR PACHAURI
VISIT PROFILE
JSP - Custom Tags
JSP - Syntax
JSP ENVIRONMENT SETUP
JSP - Http Status Codes
About JSP(Java Server Pages)
JSP - Page Redirecting
July 22, 2017
July 22, 2017
July 22, 2017
July 22, 2017
July 22, 2017
July 22, 2017
Powered by Blogger
Theme images by badins
Powered By Technowariors,The Next Gen Technologists
In this chapter, we will discuss the Custom Tags in JSP. A custom tag is a user-de ned JSP language element. When a
JSP page containing a custom tag is translated into a servlet, the tag is converted to operations on an object called a tag
handler. The Web container then invokes those operations when the JSP page's servlet is executed. JSP tag extensions …
READ MORE
In this chapter, we will discuss Syntax in JSP. We will understand the basic use of simple syntax (i.e,
elements) involved with JSP development. Elements of JSP The elements of JSP have been described
below − The Scriptlet A scriptlet can contain any number of JAVA language statements, variable or …
READ MORE
A development environment is where you would develop your JSP programs, test them and nally run
them. This tutorial will guide you to setup your JSP development environment which involves the
following steps − Setting up Java Development Kit This step involves downloading an implementation …
READ MORE
In this chapter, we will discuss the Http Status Codes in JSP. The format of the HTTP request and the HTTP response
messages are similar and will have the following structure − An initial status line + CRLF (Carriage Return + Line Feed ie.
New Line) Zero or more header lines + CRLF A blank line ie. a CRLF An optional message body like le, query data or query…
READ MORE
What is JSP(Java Server Pages) Java Server Pages (JSP) is a server-side programming technology that enables the
creation of dynamic, platform-independent method for building Web-based applications. JSP have access to the entire
family of Java APIs, including the JDBC API to access enterprise databases. This tutorial will teach you how to use Java …
READ MORE
In this chapter, we will discuss page redirecting with JSP. Page redirection is generally used when a document moves to a
new location and we need to send the client to this new location. This can be because of load balancing, or for simple
randomization. The simplest way of redirecting a request to another page is by using sendRedirect() method of response…
READ MORE
7/23/2017 JSP - Session Tracking
https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 5/5
JSP - Sending Email
JSP - Standard Tag Library (JSTL)
Tutorial
JSP - Database Access
JSP - XML Data
JSP - JavaBeans
JSP - Custom Tags
JSP - Expression Language (EL)
JSP - Exception Handling
JSP - Debugging
JSP - Security
JSP - Internationalization| i18n|
l10n
Archive
Report Abuse
Ad

More Related Content

What's hot (20)

Web application finger printing - whitepaper
Web application finger printing - whitepaperWeb application finger printing - whitepaper
Web application finger printing - whitepaper
Anant Shrivastava
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
Aleksandar Ilić
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
UdaAs PaNchi
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
okelloerick
 
QuickConnect
QuickConnectQuickConnect
QuickConnect
Annu G
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
Mudasir Syed
 
Php session
Php sessionPhp session
Php session
argusacademy
 
Cache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From RubyCache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From Ruby
Molly Struve
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
J2EE jsp_03
J2EE jsp_03J2EE jsp_03
J2EE jsp_03
Biswabrata Banerjee
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJS
robertjd
 
Token Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJSToken Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJS
Hüseyin BABAL
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
async_io
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Ahmed Madkor
 
Mongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.jsMongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.js
Yuriy Bogomolov
 
Building Secure User Interfaces With JWTs
Building Secure User Interfaces With JWTsBuilding Secure User Interfaces With JWTs
Building Secure User Interfaces With JWTs
robertjd
 
2016 pycontw web api authentication
2016 pycontw web api authentication 2016 pycontw web api authentication
2016 pycontw web api authentication
Micron Technology
 
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump Start
Haim Michael
 
Client side
Client sideClient side
Client side
Михаил Фирстов
 
Web application finger printing - whitepaper
Web application finger printing - whitepaperWeb application finger printing - whitepaper
Web application finger printing - whitepaper
Anant Shrivastava
 
Java Svet - Communication Between Android App Components
Java Svet - Communication Between Android App ComponentsJava Svet - Communication Between Android App Components
Java Svet - Communication Between Android App Components
Aleksandar Ilić
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
UdaAs PaNchi
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
okelloerick
 
QuickConnect
QuickConnectQuickConnect
QuickConnect
Annu G
 
Cache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From RubyCache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From Ruby
Molly Struve
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJS
robertjd
 
Token Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJSToken Based Authentication Systems with AngularJS & NodeJS
Token Based Authentication Systems with AngularJS & NodeJS
Hüseyin BABAL
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
async_io
 
Mongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.jsMongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.js
Yuriy Bogomolov
 
Building Secure User Interfaces With JWTs
Building Secure User Interfaces With JWTsBuilding Secure User Interfaces With JWTs
Building Secure User Interfaces With JWTs
robertjd
 
2016 pycontw web api authentication
2016 pycontw web api authentication 2016 pycontw web api authentication
2016 pycontw web api authentication
Micron Technology
 
WebSockets Jump Start
WebSockets Jump StartWebSockets Jump Start
WebSockets Jump Start
Haim Michael
 

Similar to Jsp session tracking (20)

Session Tracking in servlets
Session Tracking in servletsSession Tracking in servlets
Session Tracking in servlets
chauhankapil
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Divyam Pateriya
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
Programmer Blog
 
Session 33 - Session Management using other Techniques
Session 33 - Session Management using other TechniquesSession 33 - Session Management using other Techniques
Session 33 - Session Management using other Techniques
PawanMM
 
self des session_T_M
self des session_T_Mself des session_T_M
self des session_T_M
Dayasagar Kadam
 
Session tracking In Java
Session tracking In JavaSession tracking In Java
Session tracking In Java
honeyvachharajani
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
vantinhkhuc
 
Major project report
Major project reportMajor project report
Major project report
Omprakash Dhakad
 
Basics Of Servlet
Basics Of ServletBasics Of Servlet
Basics Of Servlet
Shubhani Jain
 
Lecture8
Lecture8Lecture8
Lecture8
Châu Thanh Chương
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
Techglyphs
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
WebStackAcademy
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
baabtra.com - No. 1 supplier of quality freshers
 
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.pptGAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
CUO VEERANAN VEERANAN
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)
kunjan shah
 
Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectos
Manuel Menezes de Sequeira
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
HumphreyOwuor1
 
servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0
megrhi haikel
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
People Strategists
 
Session And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaSession And Cookies In Servlets - Java
Session And Cookies In Servlets - Java
JainamParikh3
 
Session Tracking in servlets
Session Tracking in servletsSession Tracking in servlets
Session Tracking in servlets
chauhankapil
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Divyam Pateriya
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
Programmer Blog
 
Session 33 - Session Management using other Techniques
Session 33 - Session Management using other TechniquesSession 33 - Session Management using other Techniques
Session 33 - Session Management using other Techniques
PawanMM
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
vantinhkhuc
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
Techglyphs
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
WebStackAcademy
 
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.pptGAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
GAC Java Presentation_Server Side Include_Cookies_Filters 2022.ppt
CUO VEERANAN VEERANAN
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)
kunjan shah
 
Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectos
Manuel Menezes de Sequeira
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
HumphreyOwuor1
 
servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0
megrhi haikel
 
Session And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaSession And Cookies In Servlets - Java
Session And Cookies In Servlets - Java
JainamParikh3
 
Ad

Recently uploaded (20)

How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Ad

Jsp session tracking

  • 1. 7/23/2017 JSP - Session Tracking https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 1/5 Classic Codes & Dashing Developer (Ashok Kumar Pachauri) originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms. we are working our way to adding fresh tutorials to our repository which now proudly aunts a wealth of tutorials and allied articles on topics ranging from programming languages to web designing to academics and much more. JSP - Session Tracking July 22, 2017 In this chapter, we will discuss session tracking in JSP. HTTP is a "stateless" protocol which means each time a client retrieves a Webpage, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request. Let us now discuss a few options to maintain the session between the Web Client and the Web Server − A webserver can assign a unique session ID as a cookie to each web client and for subsequent requests from the client they can be recognized using the received cookie. This may not be an effective way as the browser at times does not support a cookie. It is not recommended to use this procedure to maintain the sessions. A web server can send a hidden HTML form field along with a unique session ID as follows − <input type = "hidden" name = "sessionid" value = "12345"> This entry means that, when the form is submitted, the specified name and value are automatically included in the GET or the POST data. Each time the web browser sends the request back, the session_id value can be used to keep the track of different web browsers. This can be an effective way of keeping track of the session but clicking on a regular (<A HREF...>) hypertext link does not result in a form submission, so hidden form fields also cannot support general session tracking. You can append some extra data at the end of each URL. This data identifies the session; the server can associate that session identifier with the data it has stored about that session. For example, with http://tutorialspoint.com/file.htm;sessionid=12345, the session identifier is attached as sessionid = 12345 which can be accessed at the web server to identify the client. URL rewriting is a better way to maintain sessions and works for the browsers when they don't support cookies. The drawback here is that you will have to generate every URL dynamically to assign a session ID though page is a simple static HTML page. Apart from the above mentioned options, JSP makes use of the servlet provided HttpSession Interface. This interface provides a way to identify a user across. a one page request or visit to a website or store information about that user By default, JSPs have session tracking enabled and a new HttpSession object is instantiated for each new client automatically. Disabling session tracking requires explicitly turning it off by setting the page directive session attribute to false as follows − <%@ page session = "false" %> The JSP engine exposes the HttpSession object to the JSP author through the implicit session object. Since session object is already provided to the JSP programmer, the programmer can immediately begin storing and retrieving data from the object without any initialization or getSession(). Here is a summary of important methods available through the session object − S.No. Method & Description 1 public Object getAttribute(String name) This method returns the object bound with the specified name in this session, or null if no object is bound under the name. 2 public Enumeration getAttributeNames() This method returns an Enumeration of String objects containing the names of all the objects bound to this session. 3 public long getCreationTime() This method returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT. public String getId() Maintaining Session Between Web Client And Server Cookies Hidden Form Fields URL Rewriting The session Object
  • 2. 7/23/2017 JSP - Session Tracking https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 2/5 4 public String getId() This method returns a string containing the unique identifier assigned to this session. 5 public long getLastAccessedTime() This method returns the last time the client sent a request associated with the this session, as the number of milliseconds since midnight January 1, 1970 GMT. 6 public int getMaxInactiveInterval() This method returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. 7 public void invalidate() This method invalidates this session and unbinds any objects bound to it. 8 public boolean isNew() This method returns true if the client does not yet know about the session or if the client chooses not to join the session. 9 public void removeAttribute(String name) This method removes the object bound with the specified name from this session. 10 public void setAttribute(String name, Object value) This method binds an object to this session, using the name specified. 11 public void setMaxInactiveInterval(int interval) This method specifies the time, in seconds, between client requests before the servlet container will invalidate this session. This example describes how to use the HttpSession object to find out the creation time and the last- accessed time for a session. We would associate a new session with the request if one does not already exist. <%@ page import = "java.io.*,java.util.*" %> <% // Get session creation time. Date createTime = new Date(session.getCreationTime()); // Get last access time of this Webpage. Date lastAccessTime = new Date(session.getLastAccessedTime()); String title = "Welcome Back to my website"; Integer visitCount = new Integer(0); String visitCountKey = new String("visitCount"); String userIDKey = new String("userID"); String userID = new String("ABCD"); // Check if this is new comer on your Webpage. if (session.isNew() ){ title = "Welcome to my website"; session.setAttribute(userIDKey, userID); session.setAttribute(visitCountKey, visitCount); } visitCount = (Integer)session.getAttribute(visitCountKey); visitCount = visitCount + 1; userID = (String)session.getAttribute(userIDKey); session.setAttribute(visitCountKey, visitCount); %> <html> <head> <title>Session Tracking</title> </head> <body> <center> <h1>Session Tracking</h1> </center> <table border = "1" align = "center"> <tr bgcolor = "#949494"> <th>Session info</th> <th>Value</th> </tr> <tr> <td>id</td> <td><% out.print( session.getId()); %></td> </tr> <tr> <td>Creation Time</td> <td><% out.print(createTime); %></td> </tr> <tr> <td>Time of Last Access</td> <td><% out.print(lastAccessTime); %></td> </tr> <tr> <td>User ID</td> <td><% out.print(userID); %></td> </tr> <tr> <td>Number of visits</td> <td><% out.print(visitCount); %></td> </tr> </table> </body> </html> Now put the above code in main.jsp and try to access http://localhost:8080/main.jsp. Once you run the URL, you will receive the following result − Session Information Session info value id 0AE3EC93FF44E3C525B4351B77ABB2D5 Creation Time Tue Jun 08 17:26:40 GMT+04:00 2010 Time of Last Access Tue Jun 08 17:26:40 GMT+04:00 2010 User ID ABCD Session Tracking Example Welcome to my website
  • 3. 7/23/2017 JSP - Session Tracking https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 3/5 JSP - Internationalization| i18n| l10n JSP - Handling Date JSP - Standard Tag Library (JSTL) Tutorial No comments yet Add a comment as Ashok kumar Pachauri (Dashing Developer) Popular posts from this blog July 22, 2017 July 22, 2017 July 22, 2017 User ID ABCD Number of visits 0 Now try to run the same JSP for the second time, you will receive the following result. Session Information info type value id 0AE3EC93FF44E3C525B4351B77ABB2D5 Creation Time Tue Jun 08 17:26:40 GMT+04:00 2010 Time of Last Access Tue Jun 08 17:26:40 GMT+04:00 2010 User ID ABCD Number of visits 1 When you are done with a user's session data, you have several options − Remove a particular attribute − You can call the public void removeAttribute(String name) method to delete the value associated with the a particular key. Delete the whole session − You can call the public void invalidate() method to discard an entire session. Setting Session timeout − You can call the public void setMaxInactiveInterval(int interval) method to set the timeout for a session individually. Log the user out − The servers that support servlets 2.4, you can call logout to log the client out of the Web server and invalidate all sessions belonging to all the users. web.xml Configuration − If you are using Tomcat, apart from the above mentioned methods, you can configure the session time out in web.xml file as follows. <session-config> <session-timeout>15</session-timeout> </session-config> The timeout is expressed as minutes, and overrides the default timeout which is 30 minutes in Tomcat. The getMaxInactiveInterval( ) method in a servlet returns the timeout period for that session in seconds. So if your session is configured in web.xml for 15 minutes, getMaxInactiveInterval( ) returns 900. Welcome Back to my website Deleting Session Data In this chapter, we will discuss the concept of Internationalization in JSP. Before we proceed, let us understand the following three important terms − Internationalization (i18n) − This means enabling a website to provide different versions of content translated into the visitor's language or nationality. Localization (l10n) − This means adding resources to a … READ MORE In this chapter, we will discuss how to handle data in JSP. One of the most important advantages of using JSP is that you can use all the methods available in core Java. We will take you through the Date class which is available in the java.util package; this class encapsulates the current date and time. The Date class supports two constructors. The … READ MORE In this chapter, we will understand the different tags in JSP. The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates the core functionality common to many JSP applications. JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, … READ MORE
  • 4. 7/23/2017 JSP - Session Tracking https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 4/5 Translate Select Language ▼ Following 9 Pages Home Introduction To JSP JSP ENVIRONMENT SETUP JSP ARCHITECTURE JSP Life Cycle JSP SYNTAX JSP Directives JSP ACTIONS JSP - Implicit Objects JSP - Client Request JSP - Server Response JSP - Http Status Codes JSP - Form Processing JSP - Filters JSP - Cookies Handling JSP - Session Tracking JSP - File Uploading JSP - Handling Date JSP - Page Redirecting JSP - Hits Counter JSP - Auto Refresh ASHOK KUMAR PACHAURI VISIT PROFILE JSP - Custom Tags JSP - Syntax JSP ENVIRONMENT SETUP JSP - Http Status Codes About JSP(Java Server Pages) JSP - Page Redirecting July 22, 2017 July 22, 2017 July 22, 2017 July 22, 2017 July 22, 2017 July 22, 2017 Powered by Blogger Theme images by badins Powered By Technowariors,The Next Gen Technologists In this chapter, we will discuss the Custom Tags in JSP. A custom tag is a user-de ned JSP language element. When a JSP page containing a custom tag is translated into a servlet, the tag is converted to operations on an object called a tag handler. The Web container then invokes those operations when the JSP page's servlet is executed. JSP tag extensions … READ MORE In this chapter, we will discuss Syntax in JSP. We will understand the basic use of simple syntax (i.e, elements) involved with JSP development. Elements of JSP The elements of JSP have been described below − The Scriptlet A scriptlet can contain any number of JAVA language statements, variable or … READ MORE A development environment is where you would develop your JSP programs, test them and nally run them. This tutorial will guide you to setup your JSP development environment which involves the following steps − Setting up Java Development Kit This step involves downloading an implementation … READ MORE In this chapter, we will discuss the Http Status Codes in JSP. The format of the HTTP request and the HTTP response messages are similar and will have the following structure − An initial status line + CRLF (Carriage Return + Line Feed ie. New Line) Zero or more header lines + CRLF A blank line ie. a CRLF An optional message body like le, query data or query… READ MORE What is JSP(Java Server Pages) Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications. JSP have access to the entire family of Java APIs, including the JDBC API to access enterprise databases. This tutorial will teach you how to use Java … READ MORE In this chapter, we will discuss page redirecting with JSP. Page redirection is generally used when a document moves to a new location and we need to send the client to this new location. This can be because of load balancing, or for simple randomization. The simplest way of redirecting a request to another page is by using sendRedirect() method of response… READ MORE
  • 5. 7/23/2017 JSP - Session Tracking https://ashokpachauri.blogspot.com/2017/07/jsp-session-tracking.html 5/5 JSP - Sending Email JSP - Standard Tag Library (JSTL) Tutorial JSP - Database Access JSP - XML Data JSP - JavaBeans JSP - Custom Tags JSP - Expression Language (EL) JSP - Exception Handling JSP - Debugging JSP - Security JSP - Internationalization| i18n| l10n Archive Report Abuse