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

PPT
Java servlet life cycle - methods ppt
kamal kotecha
 
PPTX
java Servlet technology
Tanmoy Barman
 
PPT
Java Servlet
Rajiv Gupta
 
PPT
Java servlets
lopjuan
 
PPTX
Javax.servlet,http packages
vamsi krishna
 
PDF
Servlet and servlet life cycle
Dhruvin Nakrani
 
PPTX
Java Servlets
KushagraChadha1
 
PPT
Servlet ppt by vikas jagtap
Vikas Jagtap
 
Java servlet life cycle - methods ppt
kamal kotecha
 
java Servlet technology
Tanmoy Barman
 
Java Servlet
Rajiv Gupta
 
Java servlets
lopjuan
 
Javax.servlet,http packages
vamsi krishna
 
Servlet and servlet life cycle
Dhruvin Nakrani
 
Java Servlets
KushagraChadha1
 
Servlet ppt by vikas jagtap
Vikas Jagtap
 

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
 
Ad

Similar to Java - Servlet - Mazenet Solution (20)

PPTX
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
PDF
Adv java unit 4 M.Sc CS.pdf
KALAISELVI P
 
PPTX
J2ee servlet
vinoth ponnurangam
 
PDF
Lecture 3: Servlets - Session Management
Fahad Golra
 
PPTX
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
PPTX
J2EE : Java servlet and its types, environment
joearunraja2
 
PDF
Bt0083 server side programing
Techglyphs
 
PPTX
IP UNIT III PPT.pptx
ssuser92282c
 
PPTX
Servlet session 9
Anuj Singh Rajput
 
PPTX
Servlets-UNIT3and introduction to servlet
RadhikaP41
 
PPTX
Wt unit 3
team11vgnt
 
PPT
Basics Of Servlet
Shubhani Jain
 
PPTX
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
PPTX
SessionTrackServlets.pptx
Ranjeet Reddy
 
PPTX
SERVIET
sathish sak
 
PDF
Servlets
Abdalla Mahmoud
 
PDF
Servlet sessions
vantinhkhuc
 
PPTX
SCWCD : Servlet web applications : CHAP 3
Ben Abdallah Helmi
 
PDF
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
PPTX
Session tracking in servlets
vishal choudhary
 
servlets sessions and cookies, jdbc connectivity
snehalatha790700
 
Adv java unit 4 M.Sc CS.pdf
KALAISELVI P
 
J2ee servlet
vinoth ponnurangam
 
Lecture 3: Servlets - Session Management
Fahad Golra
 
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
J2EE : Java servlet and its types, environment
joearunraja2
 
Bt0083 server side programing
Techglyphs
 
IP UNIT III PPT.pptx
ssuser92282c
 
Servlet session 9
Anuj Singh Rajput
 
Servlets-UNIT3and introduction to servlet
RadhikaP41
 
Wt unit 3
team11vgnt
 
Basics Of Servlet
Shubhani Jain
 
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
SessionTrackServlets.pptx
Ranjeet Reddy
 
SERVIET
sathish sak
 
Servlets
Abdalla Mahmoud
 
Servlet sessions
vantinhkhuc
 
SCWCD : Servlet web applications : CHAP 3
Ben Abdallah Helmi
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
Session tracking in servlets
vishal choudhary
 
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
 

Recently uploaded (20)

DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 

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)