SlideShare a Scribd company logo
Servlets
By
Sharmilee J
Java Trainer
Mazenet Solution
ServletConfig
Servlet config Interface
• An object of ServletConfig is created by the web
container for each servlet.
• This object can be used to get configuration
information from web.xml file
Advantage:
• No need to update in web.xml if any changes
occurs.
Method:
getServletConfig()
Syntax: public ServletConfig getServletConfig();
<web-app>
<servlet>
<init-param>
<param-name>parametername</param-name>
<param-value>parametervalue</param-value>
</init-param>
</servlet>
</web-app>
ServletContext
ServletContext Interface
• An object of ServletContext is created by the
web container at time of deploying the project
• <context-param>element is used
Method:
getServletContext() method of ServletConfig
interface returns the object of ServletContext.
Syntax:
public ServletContext getServletContext()
<web-app>
......
<context-param>
<param-name>parametername</param-name>
<param-value>parametervalue</param-value>
</context-param>
......
</web-app>
Diff between ServletConfig & ServletContext
ServletConfig ServletContext
ServletConfig available
in javax.servlet.*; package
ServletContext available in
javax.servlet.*; package
ServletConfig object is one per servlet
class
ServletContext object is global to
entire web application
Object of ServletConfig will be created
during initialization process of the
servlet
Object of ServletContext will be
created at the time of web
application deployment
Scope: As long as a servlet is
executing, ServletConfig object will be
available, it will be destroyed once the
servlet execution is completed.
Scope: As long as web application is
executing, ServletContext object will
be available, and it will be destroyed
once the application is removed from
the server.
We should give request explicitly, in
order to create ServletConfig object for
the first time
ServletContext object will be available
even before giving the first request
In web.xml – <init-param> tag will be
appear under <servlet-class> tag
In web.xml – <context-param> tag will
be appear under <web-app> tag
Session Tracking
Session Tracking
• Session refers a particular interval of time.
• Session tracking is used to maintain the state
of an user. It is known as session management.
Session Tracking Techniques:
There are four techniques used in Session
tracking:
• Cookies
• Hidden Form Field
• URL Rewriting
• HttpSession
1. cookies
Cookies
• It is a piece of information.
• In cookies, request from same client is not
considered as the new request.
Types of cookies.
1. Non-Persistent cookie.
Valid for single session
2.Persistent cookie.
Valid for multiple session.
Advantage of Cookies:
• State maintenance
Disadvantages:
• Cookie can be disabled from the browser.
• Only textual information can be set.
Cookie creation:
• Cookie ck=new Cookie("user","sonoo jaiswal");
//creating cookie object
• response.addCookie(ck);
//adding cookie in the response
Cookie deletion:
• Cookie ck=new Cookie("user","");
//deleting value of cookie
• ck.setMaxAge(0);
//changing the maximum age to 0 seconds
• response.addCookie(ck);
//adding cookie in the response
2. Hidden Form Field
Hidden Form field
• We store the information in the hidden field
and get it from another servlet.
<input type="hidden" name="uname" value=“java">
Advantage:
• Work when the cookie is disabled.
Disadvantages:
• Only textual information can be sent.
• Maintained at server side.
3. URL Rewriting
URL Rewriting
• Appending session ID to the url is known as
url Rewriting.
• We implement url rewriting by caling,
response.encodeURL(String url);
Advantage:
• Work when the cookie is disabled.
• No form submission is not required as in case
of hidden form field.
4. HTTP Session
Http Session
• Used to view and manipulate information
about a session, such as the session identifier,
creation time, and last accessed time.
• HttpSession session=request.getSession();
Servlet Filters
Servlet Filters
• A filter is an object that is invoked at the
preprocessing and postprocessing of a request.
• servlet filter is pluggable, i.e if we remove filter in
web.xml, filter is automatically removed.
Advantage
• Encryption and decryption
• Input validation
• Recording all incoming requests
Filter API
Three interfaces:
• Filter
• FilterChain
• FilterConfig
Filter interface life cycle methods:
1.init(filterConfig)
2.doFilter(ServletRequest,ServletResponse,FilterChain)
3.destroy()
FilterConfig interface life cycle methods:
1.getInitParameter()
2.getInitParameterNames()
3.getServletContext()
4.getFilterName()
FilterChain interface life cycle method:
1.doFilter(ServletRequest,ServletResponse)
Java - Servlet - Mazenet Solution

More Related Content

What's hot (20)

PPTX
Servlets
Geethu Mohan
 
PPT
An Introduction To Java Web Technology
vikram singh
 
PPT
JAVA Servlets
deepak kumar
 
PPT
Servlet/JSP course chapter 1: Introduction to servlets
JavaEE Trainers
 
PPTX
Servlets
ZainabNoorGul
 
PPT
Java Servlets
BG Java EE Course
 
PPTX
Servletarchitecture,lifecycle,get,post
vamsi krishna
 
DOCX
Servlet
Dhara Joshi
 
PPTX
Servlets
Rajkiran Mummadi
 
PPT
Servlets
Sasidhar Kothuru
 
PPTX
Session And Cookies In Servlets - Java
JainamParikh3
 
PPTX
Java Servlets
Emprovise
 
RTF
Servlet lifecycle
Durga Devi Thulluri
 
PPT
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
PPT
Programming Server side with Sevlet
backdoor
 
PPTX
Servlets
Akshay Ballarpure
 
PPTX
Chapter 3 servlet & jsp
Jafar Nesargi
 
PPTX
Core web application development
Bahaa Farouk
 
PDF
Java servlets
Mukesh Tekwani
 
PDF
JEE Programming - 04 Java Servlets
Danairat Thanabodithammachari
 
Servlets
Geethu Mohan
 
An Introduction To Java Web Technology
vikram singh
 
JAVA Servlets
deepak kumar
 
Servlet/JSP course chapter 1: Introduction to servlets
JavaEE Trainers
 
Servlets
ZainabNoorGul
 
Java Servlets
BG Java EE Course
 
Servletarchitecture,lifecycle,get,post
vamsi krishna
 
Servlet
Dhara Joshi
 
Session And Cookies In Servlets - Java
JainamParikh3
 
Java Servlets
Emprovise
 
Servlet lifecycle
Durga Devi Thulluri
 
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
Programming Server side with Sevlet
backdoor
 
Chapter 3 servlet & jsp
Jafar Nesargi
 
Core web application development
Bahaa Farouk
 
Java servlets
Mukesh Tekwani
 
JEE Programming - 04 Java Servlets
Danairat Thanabodithammachari
 

Similar to Java - Servlet - Mazenet Solution (20)

PDF
Adv java unit 4 M.Sc CS.pdf
KALAISELVI P
 
PPTX
SessionTrackServlets.pptx
Ranjeet Reddy
 
PPTX
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
yvtinsane
 
PPTX
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
PPTX
yrs of IT experience in enterprise programming
narasimhulum1623
 
PPT
session and cookies.ppt
Jayaprasanna4
 
PPTX
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
PPT
Ecom2
Santosh Pandey
 
PPTX
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
PPTX
Chapter 8 part1
application developer
 
PPTX
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
PDF
ASP.NET-Web Programming - Sessions and Cookies
baabtra.com - No. 1 supplier of quality freshers
 
PDF
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
PPTX
J2EE : Java servlet and its types, environment
joearunraja2
 
PPTX
UNIT - 5.pptx Servlets And Database Connectivity
bmit1
 
PPTX
Advance java session 7
Smita B Kumar
 
PPTX
Session tracking in servlets
vishal choudhary
 
PDF
Bt0083 server side programing
Techglyphs
 
PPTX
IP UNIT III PPT.pptx
ssuser92282c
 
PPTX
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
Adv java unit 4 M.Sc CS.pdf
KALAISELVI P
 
SessionTrackServlets.pptx
Ranjeet Reddy
 
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
yvtinsane
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
yrs of IT experience in enterprise programming
narasimhulum1623
 
session and cookies.ppt
Jayaprasanna4
 
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
19_JavaScript - Storage_Cookies_students.pptx
VatsalJain39
 
Chapter 8 part1
application developer
 
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
ASP.NET-Web Programming - Sessions and Cookies
baabtra.com - No. 1 supplier of quality freshers
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
J2EE : Java servlet and its types, environment
joearunraja2
 
UNIT - 5.pptx Servlets And Database Connectivity
bmit1
 
Advance java session 7
Smita B Kumar
 
Session tracking in servlets
vishal choudhary
 
Bt0083 server side programing
Techglyphs
 
IP UNIT III PPT.pptx
ssuser92282c
 
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
Ad

More from Mazenetsolution (20)

PPTX
Tally Auto E-mail Module | Mazenet Technologies
Mazenetsolution
 
PPTX
Tally Auto SMS Module| Mazenet Technologies
Mazenetsolution
 
PPTX
Tally auto synchronization
Mazenetsolution
 
PPTX
Print barcode using voucher- Mazenettechnologies
Mazenetsolution
 
PPTX
Copy user list | Tally | Tally Software | Accounting Software | Mazenet
Mazenetsolution
 
PPTX
Auto synchronization | Tally Software | Mazenet Technologies
Mazenetsolution
 
PPTX
Auto backup | Tally Coimbatore | Tally Software
Mazenetsolution
 
PPTX
Mazenet Technologies-Tally
Mazenetsolution
 
PPTX
Android - Intents - Mazenet Solution
Mazenetsolution
 
PPT
Software Testing - Tool support for testing (CAST) - Mazenet Solution
Mazenetsolution
 
PPT
Software Testing - Test management - Mazenet Solution
Mazenetsolution
 
PPTX
Red Hat - LVM - Mazenet Solution
Mazenetsolution
 
PPT
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
PPT
Static testing techniques
Mazenetsolution
 
PPTX
Java- GUI- Mazenet solution
Mazenetsolution
 
PPT
Oracle- Introduction to Sql commands- Mazenet solution
Mazenetsolution
 
PPTX
Process management in linux
Mazenetsolution
 
PPT
Software Testing- Principles of testing- Mazenet Solution
Mazenetsolution
 
PPTX
Java- JDBC- Mazenet Solution
Mazenetsolution
 
PPT
Software Testing-Dynamic testing technique-Mazenet solution
Mazenetsolution
 
Tally Auto E-mail Module | Mazenet Technologies
Mazenetsolution
 
Tally Auto SMS Module| Mazenet Technologies
Mazenetsolution
 
Tally auto synchronization
Mazenetsolution
 
Print barcode using voucher- Mazenettechnologies
Mazenetsolution
 
Copy user list | Tally | Tally Software | Accounting Software | Mazenet
Mazenetsolution
 
Auto synchronization | Tally Software | Mazenet Technologies
Mazenetsolution
 
Auto backup | Tally Coimbatore | Tally Software
Mazenetsolution
 
Mazenet Technologies-Tally
Mazenetsolution
 
Android - Intents - Mazenet Solution
Mazenetsolution
 
Software Testing - Tool support for testing (CAST) - Mazenet Solution
Mazenetsolution
 
Software Testing - Test management - Mazenet Solution
Mazenetsolution
 
Red Hat - LVM - Mazenet Solution
Mazenetsolution
 
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
Static testing techniques
Mazenetsolution
 
Java- GUI- Mazenet solution
Mazenetsolution
 
Oracle- Introduction to Sql commands- Mazenet solution
Mazenetsolution
 
Process management in linux
Mazenetsolution
 
Software Testing- Principles of testing- Mazenet Solution
Mazenetsolution
 
Java- JDBC- Mazenet Solution
Mazenetsolution
 
Software Testing-Dynamic testing technique-Mazenet solution
Mazenetsolution
 
Ad

Recently uploaded (20)

PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
infertility, types,causes, impact, and management
Ritu480198
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Horarios de distribución de agua en julio
pegazohn1978
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 

Java - Servlet - Mazenet Solution

  • 3. Servlet config Interface • An object of ServletConfig is created by the web container for each servlet. • This object can be used to get configuration information from web.xml file Advantage: • No need to update in web.xml if any changes occurs. Method: getServletConfig()
  • 4. Syntax: public ServletConfig getServletConfig(); <web-app> <servlet> <init-param> <param-name>parametername</param-name> <param-value>parametervalue</param-value> </init-param> </servlet> </web-app>
  • 6. ServletContext Interface • An object of ServletContext is created by the web container at time of deploying the project • <context-param>element is used Method: getServletContext() method of ServletConfig interface returns the object of ServletContext. Syntax: public ServletContext getServletContext()
  • 8. Diff between ServletConfig & ServletContext ServletConfig ServletContext ServletConfig available in javax.servlet.*; package ServletContext available in javax.servlet.*; package ServletConfig object is one per servlet class ServletContext object is global to entire web application Object of ServletConfig will be created during initialization process of the servlet Object of ServletContext will be created at the time of web application deployment Scope: As long as a servlet is executing, ServletConfig object will be available, it will be destroyed once the servlet execution is completed. Scope: As long as web application is executing, ServletContext object will be available, and it will be destroyed once the application is removed from the server. We should give request explicitly, in order to create ServletConfig object for the first time ServletContext object will be available even before giving the first request In web.xml – <init-param> tag will be appear under <servlet-class> tag In web.xml – <context-param> tag will be appear under <web-app> tag
  • 10. Session Tracking • Session refers a particular interval of time. • Session tracking is used to maintain the state of an user. It is known as session management.
  • 11. Session Tracking Techniques: There are four techniques used in Session tracking: • Cookies • Hidden Form Field • URL Rewriting • HttpSession
  • 13. Cookies • It is a piece of information. • In cookies, request from same client is not considered as the new request.
  • 14. Types of cookies. 1. Non-Persistent cookie. Valid for single session 2.Persistent cookie. Valid for multiple session. Advantage of Cookies: • State maintenance Disadvantages: • Cookie can be disabled from the browser. • Only textual information can be set.
  • 15. Cookie creation: • Cookie ck=new Cookie("user","sonoo jaiswal"); //creating cookie object • response.addCookie(ck); //adding cookie in the response Cookie deletion: • Cookie ck=new Cookie("user",""); //deleting value of cookie • ck.setMaxAge(0); //changing the maximum age to 0 seconds • response.addCookie(ck); //adding cookie in the response
  • 16. 2. Hidden Form Field
  • 17. Hidden Form field • We store the information in the hidden field and get it from another servlet. <input type="hidden" name="uname" value=“java"> Advantage: • Work when the cookie is disabled. Disadvantages: • Only textual information can be sent. • Maintained at server side.
  • 19. URL Rewriting • Appending session ID to the url is known as url Rewriting. • We implement url rewriting by caling, response.encodeURL(String url); Advantage: • Work when the cookie is disabled. • No form submission is not required as in case of hidden form field.
  • 21. Http Session • Used to view and manipulate information about a session, such as the session identifier, creation time, and last accessed time. • HttpSession session=request.getSession();
  • 23. Servlet Filters • A filter is an object that is invoked at the preprocessing and postprocessing of a request. • servlet filter is pluggable, i.e if we remove filter in web.xml, filter is automatically removed. Advantage • Encryption and decryption • Input validation • Recording all incoming requests
  • 24. Filter API Three interfaces: • Filter • FilterChain • FilterConfig Filter interface life cycle methods: 1.init(filterConfig) 2.doFilter(ServletRequest,ServletResponse,FilterChain) 3.destroy()
  • 25. FilterConfig interface life cycle methods: 1.getInitParameter() 2.getInitParameterNames() 3.getServletContext() 4.getFilterName() FilterChain interface life cycle method: 1.doFilter(ServletRequest,ServletResponse)