SlideShare a Scribd company logo
SESSION – 9
By→ Anuj Kumar Singh
ServletContext Interface
1. An object of ServletContext is created by the web container at time of
deploying the project.
2. This object can be used to get configuration information from web.xml
file. There is only one ServletContext object per web application.
3. If any information is shared to many servlet, it is better to provide it
from the web.xml file using the <context-param> element.
Advantage of ServletContext
1. Easy to maintain if any information is shared to all the servlet, it is
better to make it available for all the servlet.
2. We provide this information from the web.xml file, so if the information
is changed, we don't need to modify the servlet. Thus it removes
maintenance problem.
Usage of ServletContext Interface
There can be a lot of usage of ServletContext object. Some of them
are as follows:
1. The object of ServletContext provides an interface between the
container and servlet.
2. The ServletContext object can be used to get configuration
information from the web.xml file.
3. The ServletContext object can be used to set, get or remove
attribute from the web.xml file.
4. The ServletContext object can be used to provide inter-application
communication.
Commonly used methods of ServletContext interface
1. public String getInitParameter(String name): Returns the parameter
value for the specified parameter name.
2. public Enumeration getInitParameterNames(): Returns the names of
the context's initialization parameters.
3. public void setAttribute(String name,Object object): sets the given
object in the application scope.
4. public Object getAttribute(String name): Returns the attribute for the
specified name.
5. public Enumeration getInitParameterNames(): Returns the names of
the context's initialization parameters as an Enumeration of String
objects.
6. public void removeAttribute(String name): Removes the attribute with
the given name from the servlet context
How to get the object of ServletContext interface
1. In the Servlet file use the code
ServletContext con=getServletContext();
String driver =con.getInitParameter(“driver”);
2. In the web.xml file you need to declare the context parameter, but it
should be out of any <servlet> tag. That’s why it is globally
accessible.
<context-param>
<param-name>abcd</param-name>
<param-value>Anuj Kumar Singh</param-value>
</context-param>
Example
a. NewServlet.java
b. web.xml
Output
HttpSession interface
1. Session is used to pass the information from one page to another,
like login information of website, cart information on shopping website
etc.
2. The session can be used on any servlet page by using http protocol.
3. HttpSession se=request.getSession(); // to start the session on any
page
se.setAttribute(“myname”,name); //here name is variable whose value
is stored in myname variable and can be accessed on any page.
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:
a. bind objects
b. view and manipulate information about a session, such as the
session identifier, creation time, and last accessed time.
How to get the HttpSession object ?
1. The HttpServletRequest interface provides two methods to get the
object of HttpSession:
2. public HttpSession getSession(): Returns the current session
associated with this request, or if the request does not have a
session, creates one.
3. 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.
Commonly used methods of HttpSession interface
1. public String getId(): Returns a string containing the unique identifier
value.
6. public long getCreationTime(): Returns the time when this session
was created, measured in milliseconds.
7. public long getLastAccessedTime(): Returns the last time the client
sent a request associated with this session, as the number of
milliseconds.
8. public void invalidate(): Invalidates this session then unbinds any
objects bound to it.
Example
a. NewServlet.java
b. NewServlet2.java
Output
Methods
session.invalidate();
The session.invalidate() is used to destroy the session object and can be
seen when page is refreshed once.
Servlet   session 9

More Related Content

What's hot

Scope.js prsentation
Scope.js prsentationScope.js prsentation
Scope.js prsentation
Atishay Baid
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
Learnbay Datascience
 
Krazykoder struts2 internationalization
Krazykoder struts2 internationalizationKrazykoder struts2 internationalization
Krazykoder struts2 internationalization
Krazy Koder
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
Learnbay Datascience
 
Hasgeek meteor workshop
Hasgeek meteor workshop Hasgeek meteor workshop
Hasgeek meteor workshop
Febin John James
 
Android networking in Hindi
Android networking in Hindi Android networking in Hindi
Android networking in Hindi
Vipin sharma
 
Play framework
Play frameworkPlay framework
Play framework
Keshaw Kumar
 
Dagger1
Dagger1Dagger1
Dagger1
Ramesh Akula
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
User controls
User controlsUser controls
User controls
aspnet123
 
iOS training (advanced)
iOS training (advanced)iOS training (advanced)
iOS training (advanced)
Gurpreet Singh Sachdeva
 
HasGeek Meteor Workshop
HasGeek Meteor WorkshopHasGeek Meteor Workshop
HasGeek Meteor Workshop
Febin John James
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
Varun Arora
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
Matteo Bonifazi
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
michael.labriola
 
Servlet session 8
Servlet   session 8Servlet   session 8
Servlet session 8
Anuj Singh Rajput
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
Matteo Bonifazi
 
Whirlwind tour of activiti 7
Whirlwind tour of activiti 7Whirlwind tour of activiti 7
Whirlwind tour of activiti 7
Ryan Dawson
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Security
SecuritySecurity
Security
naniix21_3
 

What's hot (20)

Scope.js prsentation
Scope.js prsentationScope.js prsentation
Scope.js prsentation
 
Python my SQL - create table
Python my SQL - create tablePython my SQL - create table
Python my SQL - create table
 
Krazykoder struts2 internationalization
Krazykoder struts2 internationalizationKrazykoder struts2 internationalization
Krazykoder struts2 internationalization
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
 
Hasgeek meteor workshop
Hasgeek meteor workshop Hasgeek meteor workshop
Hasgeek meteor workshop
 
Android networking in Hindi
Android networking in Hindi Android networking in Hindi
Android networking in Hindi
 
Play framework
Play frameworkPlay framework
Play framework
 
Dagger1
Dagger1Dagger1
Dagger1
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete
 
User controls
User controlsUser controls
User controls
 
iOS training (advanced)
iOS training (advanced)iOS training (advanced)
iOS training (advanced)
 
HasGeek Meteor Workshop
HasGeek Meteor WorkshopHasGeek Meteor Workshop
HasGeek Meteor Workshop
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
Servlet session 8
Servlet   session 8Servlet   session 8
Servlet session 8
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Whirlwind tour of activiti 7
Whirlwind tour of activiti 7Whirlwind tour of activiti 7
Whirlwind tour of activiti 7
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
Security
SecuritySecurity
Security
 

Similar to Servlet session 9

Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
People Strategists
 
SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4
Ben Abdallah Helmi
 
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
joearunraja2
 
Servlets
ServletsServlets
Servlets
Geethu Mohan
 
ServletConfig & ServletContext
ServletConfig & ServletContextServletConfig & ServletContext
ServletConfig & ServletContext
ASHUTOSH TRIVEDI
 
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
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
than sare
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
Techglyphs
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
Prof Ansari
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
Anuj Singh Rajput
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
vinoth ponnurangam
 
Servlets
ServletsServlets
Servlets
Abdalla Mahmoud
 
Lesson10 behavioral patterns
Lesson10 behavioral patternsLesson10 behavioral patterns
Lesson10 behavioral patterns
OktJona
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
Vikas Jagtap
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18
Smita B Kumar
 
OpenDMS - the first 2 weeks
OpenDMS - the first 2 weeksOpenDMS - the first 2 weeks
OpenDMS - the first 2 weeks
JPC Hanson
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring
Sunil kumar Mohanty
 
Twet
TwetTwet
Struts notes
Struts notesStruts notes
Struts notes
Rajeev Uppala
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
Thesis Scientist Private Limited
 

Similar to Servlet session 9 (20)

Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
 
SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4
 
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
 
Servlets
ServletsServlets
Servlets
 
ServletConfig & ServletContext
ServletConfig & ServletContextServletConfig & ServletContext
ServletConfig & ServletContext
 
servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0servlet 2.5 & JSP 2.0
servlet 2.5 & JSP 2.0
 
Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4Spring review_for Semester II of Year 4
Spring review_for Semester II of Year 4
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Servlets
ServletsServlets
Servlets
 
Lesson10 behavioral patterns
Lesson10 behavioral patternsLesson10 behavioral patterns
Lesson10 behavioral patterns
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
Advance java session 18
Advance java session 18Advance java session 18
Advance java session 18
 
OpenDMS - the first 2 weeks
OpenDMS - the first 2 weeksOpenDMS - the first 2 weeks
OpenDMS - the first 2 weeks
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring
 
Twet
TwetTwet
Twet
 
Struts notes
Struts notesStruts notes
Struts notes
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 

More from Anuj Singh Rajput

Web technology
Web technologyWeb technology
Web technology
Anuj Singh Rajput
 
Java script
Java scriptJava script
Java script
Anuj Singh Rajput
 
Html (hypertext markup language)
Html (hypertext markup language)Html (hypertext markup language)
Html (hypertext markup language)
Anuj Singh Rajput
 
Css
CssCss
Bootstrap
BootstrapBootstrap
Jsp session 13
Jsp   session 13Jsp   session 13
Jsp session 13
Anuj Singh Rajput
 
Jsp session 12
Jsp   session 12Jsp   session 12
Jsp session 12
Anuj Singh Rajput
 
Jsp session 11
Jsp   session 11Jsp   session 11
Jsp session 11
Anuj Singh Rajput
 
Jsp session 10
Jsp   session 10Jsp   session 10
Jsp session 10
Anuj Singh Rajput
 
Jsp session 9
Jsp   session 9Jsp   session 9
Jsp session 9
Anuj Singh Rajput
 
Jsp session 8
Jsp   session 8Jsp   session 8
Jsp session 8
Anuj Singh Rajput
 
Jsp session 7
Jsp   session 7Jsp   session 7
Jsp session 7
Anuj Singh Rajput
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
Anuj Singh Rajput
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
Anuj Singh Rajput
 
Jsp session 4
Jsp   session 4Jsp   session 4
Jsp session 4
Anuj Singh Rajput
 
Jsp session 2
Jsp   session 2Jsp   session 2
Jsp session 2
Anuj Singh Rajput
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
Anuj Singh Rajput
 
Servlet session 14
Servlet   session 14Servlet   session 14
Servlet session 14
Anuj Singh Rajput
 
Servlet session 13
Servlet   session 13Servlet   session 13
Servlet session 13
Anuj Singh Rajput
 
Servlet session 12
Servlet   session 12Servlet   session 12
Servlet session 12
Anuj Singh Rajput
 

More from Anuj Singh Rajput (20)

Web technology
Web technologyWeb technology
Web technology
 
Java script
Java scriptJava script
Java script
 
Html (hypertext markup language)
Html (hypertext markup language)Html (hypertext markup language)
Html (hypertext markup language)
 
Css
CssCss
Css
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Jsp session 13
Jsp   session 13Jsp   session 13
Jsp session 13
 
Jsp session 12
Jsp   session 12Jsp   session 12
Jsp session 12
 
Jsp session 11
Jsp   session 11Jsp   session 11
Jsp session 11
 
Jsp session 10
Jsp   session 10Jsp   session 10
Jsp session 10
 
Jsp session 9
Jsp   session 9Jsp   session 9
Jsp session 9
 
Jsp session 8
Jsp   session 8Jsp   session 8
Jsp session 8
 
Jsp session 7
Jsp   session 7Jsp   session 7
Jsp session 7
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
 
Jsp session 4
Jsp   session 4Jsp   session 4
Jsp session 4
 
Jsp session 2
Jsp   session 2Jsp   session 2
Jsp session 2
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
 
Servlet session 14
Servlet   session 14Servlet   session 14
Servlet session 14
 
Servlet session 13
Servlet   session 13Servlet   session 13
Servlet session 13
 
Servlet session 12
Servlet   session 12Servlet   session 12
Servlet session 12
 

Recently uploaded

Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Kalna College
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
andagarcia212
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
Kalna College
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
Payaamvohra1
 
Ch-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdfCh-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdf
lakshayrojroj
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
7DFarhanaMohammed
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
Kalna College
 

Recently uploaded (20)

Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
 
Ch-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdfCh-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdf
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
 

Servlet session 9

  • 1. SESSION – 9 By→ Anuj Kumar Singh
  • 2. ServletContext Interface 1. An object of ServletContext is created by the web container at time of deploying the project. 2. This object can be used to get configuration information from web.xml file. There is only one ServletContext object per web application. 3. If any information is shared to many servlet, it is better to provide it from the web.xml file using the <context-param> element. Advantage of ServletContext 1. Easy to maintain if any information is shared to all the servlet, it is better to make it available for all the servlet. 2. We provide this information from the web.xml file, so if the information is changed, we don't need to modify the servlet. Thus it removes maintenance problem.
  • 3. Usage of ServletContext Interface There can be a lot of usage of ServletContext object. Some of them are as follows: 1. The object of ServletContext provides an interface between the container and servlet. 2. The ServletContext object can be used to get configuration information from the web.xml file. 3. The ServletContext object can be used to set, get or remove attribute from the web.xml file. 4. The ServletContext object can be used to provide inter-application communication.
  • 4.
  • 5. Commonly used methods of ServletContext interface 1. public String getInitParameter(String name): Returns the parameter value for the specified parameter name. 2. public Enumeration getInitParameterNames(): Returns the names of the context's initialization parameters. 3. public void setAttribute(String name,Object object): sets the given object in the application scope. 4. public Object getAttribute(String name): Returns the attribute for the specified name. 5. public Enumeration getInitParameterNames(): Returns the names of the context's initialization parameters as an Enumeration of String objects. 6. public void removeAttribute(String name): Removes the attribute with the given name from the servlet context
  • 6. How to get the object of ServletContext interface 1. In the Servlet file use the code ServletContext con=getServletContext(); String driver =con.getInitParameter(“driver”); 2. In the web.xml file you need to declare the context parameter, but it should be out of any <servlet> tag. That’s why it is globally accessible. <context-param> <param-name>abcd</param-name> <param-value>Anuj Kumar Singh</param-value> </context-param>
  • 9. HttpSession interface 1. Session is used to pass the information from one page to another, like login information of website, cart information on shopping website etc. 2. The session can be used on any servlet page by using http protocol. 3. HttpSession se=request.getSession(); // to start the session on any page se.setAttribute(“myname”,name); //here name is variable whose value is stored in myname variable and can be accessed on any page.
  • 10. 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: a. bind objects b. view and manipulate information about a session, such as the session identifier, creation time, and last accessed time.
  • 11. How to get the HttpSession object ? 1. The HttpServletRequest interface provides two methods to get the object of HttpSession: 2. public HttpSession getSession(): Returns the current session associated with this request, or if the request does not have a session, creates one. 3. 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. Commonly used methods of HttpSession interface 1. public String getId(): Returns a string containing the unique identifier value.
  • 12. 6. public long getCreationTime(): Returns the time when this session was created, measured in milliseconds. 7. public long getLastAccessedTime(): Returns the last time the client sent a request associated with this session, as the number of milliseconds. 8. public void invalidate(): Invalidates this session then unbinds any objects bound to it.
  • 16. session.invalidate(); The session.invalidate() is used to destroy the session object and can be seen when page is refreshed once.