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
PPTX
java Servlet technology
PPT
Java Servlet
PPT
Java servlets
PPTX
Javax.servlet,http packages
PDF
Servlet and servlet life cycle
PPTX
Java Servlets
PPT
Servlet ppt by vikas jagtap
Java servlet life cycle - methods ppt
java Servlet technology
Java Servlet
Java servlets
Javax.servlet,http packages
Servlet and servlet life cycle
Java Servlets
Servlet ppt by vikas jagtap

What's hot (20)

PPTX
Servlets
PPT
An Introduction To Java Web Technology
PPT
JAVA Servlets
PPT
Servlet/JSP course chapter 1: Introduction to servlets
PPTX
Servlets
PPT
Java Servlets
PPTX
Servletarchitecture,lifecycle,get,post
DOCX
Servlet
PPTX
PPT
PPTX
Session And Cookies In Servlets - Java
PPTX
Java Servlets
RTF
Servlet lifecycle
PPT
Knowledge Sharing : Java Servlet
PPT
Programming Server side with Sevlet
PPTX
PPTX
Chapter 3 servlet & jsp
PPTX
Core web application development
PDF
Java servlets
PDF
JEE Programming - 04 Java Servlets
Servlets
An Introduction To Java Web Technology
JAVA Servlets
Servlet/JSP course chapter 1: Introduction to servlets
Servlets
Java Servlets
Servletarchitecture,lifecycle,get,post
Servlet
Session And Cookies In Servlets - Java
Java Servlets
Servlet lifecycle
Knowledge Sharing : Java Servlet
Programming Server side with Sevlet
Chapter 3 servlet & jsp
Core web application development
Java servlets
JEE Programming - 04 Java Servlets
Ad

Similar to Java - Servlet - Mazenet Solution (20)

PDF
Adv java unit 4 M.Sc CS.pdf
PPTX
SessionTrackServlets.pptx
PPTX
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
PPTX
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
PPTX
yrs of IT experience in enterprise programming
PPT
session and cookies.ppt
PPTX
servlets sessions and cookies, jdbc connectivity
PPT
PPTX
19_JavaScript - Storage_Cookies_students.pptx
PPTX
Chapter 8 part1
PPTX
CS8651 IP Unit 3.pptx
PDF
ASP.NET-Web Programming - Sessions and Cookies
PDF
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
PPTX
J2EE : Java servlet and its types, environment
PPTX
UNIT - 5.pptx Servlets And Database Connectivity
PPTX
Advance java session 7
PPTX
Session tracking in servlets
PDF
Bt0083 server side programing
PPTX
IP UNIT III PPT.pptx
PPTX
SERVLETS (2).pptxintroduction to servlet with all servlets
Adv java unit 4 M.Sc CS.pdf
SessionTrackServlets.pptx
IMPORTANT SESSION TRACKING TECHNIQUES.pptx
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
yrs of IT experience in enterprise programming
session and cookies.ppt
servlets sessions and cookies, jdbc connectivity
19_JavaScript - Storage_Cookies_students.pptx
Chapter 8 part1
CS8651 IP Unit 3.pptx
ASP.NET-Web Programming - Sessions and Cookies
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
J2EE : Java servlet and its types, environment
UNIT - 5.pptx Servlets And Database Connectivity
Advance java session 7
Session tracking in servlets
Bt0083 server side programing
IP UNIT III PPT.pptx
SERVLETS (2).pptxintroduction to servlet with all servlets
Ad

More from Mazenetsolution (20)

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

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Institutional Correction lecture only . . .
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
RMMM.pdf make it easy to upload and study
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PDF
Business Ethics Teaching Materials for college
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
Microbial disease of the cardiovascular and lymphatic systems
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Renaissance Architecture: A Journey from Faith to Humanism
Institutional Correction lecture only . . .
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Anesthesia in Laparoscopic Surgery in India
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
RMMM.pdf make it easy to upload and study
PPH.pptx obstetrics and gynecology in nursing
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Week 4 Term 3 Study Techniques revisited.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
Business Ethics Teaching Materials for college
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
Microbial disease of the cardiovascular and lymphatic systems

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)