SlideShare a Scribd company logo
1 of 23
FILTERS
WHAT IS FILTERS?
• Java class that is called for responding to requests for
resources(Servlet / JSP)
• Dynamically change the behaviour of the resource
• Intercept and process the requests
• Process the responses after responses has been generated by
servlet
• Encapsulates and modifies values of request, response or header
• Introduced in Servlet 2.3 specification
EXPLORING THE NEED OF
FILTERS
• Suppose application is in the format of Excel.
• At later point of time, clients may require it in another format
like PDF, HTML etc.
• Instead of modifying code every time, filter can be created to
transform data dynamically in required formats.
FEATURE AND UTILITY
• Main feature : Reusabilty
• Situations where filters are used:
1. Security verification
2. Logging operations
3. Session validation
4. Encryption
EXPLORING THE WORKING OF
FILTERS
1. When a request is sent for specific resource, request is
intercepted by a filter.
2. To intercept a request, a filter should have access to HTTP
request and response objects.
3. Objects are accessed by javax.servlet.ServletRequest and
javax.servlet.ServletResponse objects
4. Needs to access the list of chained filters, which can accessed
using javax.servlet.FilterChain object.
EXPLORING FILTER API
• The Filter API includes three interfaces:
1. Filter
2. FilterConfig
3. FilterChain
FILTER INTERFACE
• A Filter can be created in an application by implementing the
javax.servlet.Filter interface.
• Filter interface calls the following methods during life cycle of a
filter:
1. Init() method
2. doFilter() method
3. Destroy() method
THE Init() METHOD
• Init() method is invoked by the web container only once when
the filter is initialized.
• Servlet container passes the FilterConfig object as a parameter
through the init() method.
Syntax:
public void init(FilterConfig filterconfig) throws
ServletException
THE doFilter() METHOD
• doFilter() method is invoked when a user requests a resource,
such as a servlet to which the filter is mapped.
• Syntax:public void doFilter(ServletRequest
request,ServletResponse response,FilterChain chain) throws
java.IOException,Servlet Exception.
THE doFilter() METHOD
doFilter() method can be implemented to perform the following
tasks:
• Examining the request.
• Carrying out input filtering by wrapping the request object with
filter content or headers.
• Carrying out output filtering by wrapping the response object
with filter content or headers.
• Invoking the next filter in filter chain by calling the FilterChain
object or blocking the request by not forwarding the
request/response pair to next filter.
destroy() METHOD
• destroy() method is invoked when the filter instance is
destroyed.
• Once the destroy() method is called by the web container,the
doFilter() method cannot be called again on this filter instance.
• destroy() method enables to release any resources held by the
filter.
FILTER LIFE CYCLE
FILTERCONFIG INTERFACE
• The FilterConfig interface used is stored the initialized data.
• The init() method of the Filter interface takes a filter
configuration object as an argument, which is an instance of
FilterConfig interface.
• The filter recieves filter configuration information during
initialization from a servlet container through the FilterConfig
object.
METHODS OF FILTERCONFIG
INTERFACE
1. getFilterName:
• Returns the filter name as assigned in Deployment Descriptor.
Syntax:
public java.lang.String getFilterName()
2. getInitParameter:
• Returns the named initialization parameter value as a string.
• A null value is returned if the parameter is not found.
• Syntax:
Public java.lang.String getInitParameter(java.lang.String name)
METHODS OF FILTERCONFIG
INTERFACE
3. getInitParameterNames:
• Returns an Enumeration of String objects.
• An empty Enumeration is returned,if no initialization parameters
are found for the filter.
Syntax:
public java.util.Enumeration getInitParameterNames().
4. getServletContext:
• Returns a reference of the ServletContext interface in which a
filter is executed.
Syntax:
publicServletContext getServletContext()
FILTERCHAIN INTERFACE
• FilterChain interface provides a mechanism to invoke a series of
filters,which are specified in filter chain,in an application.
• If the invoked filter is the last one in chain,the target resource
is invoked.
• Syntax:
• Public void doFilter(ServletRequest request,ServletResponse
response) throws java.io.IOException,ServletException.
CONFIGURING A FILTER
• web.xml is used to configure filters to resources
• Annotations- Servlet 3.0
• Deployment descriptor used for defining configuration and
mapping for filters and servlets
• Use of annotations eliminates the need of deployment
descriptor
CONFIGURING FILTERS USING
DEPLOYMENT DESCRIPTOR
• Deployment descriptor is located in WEB-INF directory of the
web application.
• Used to declare and map the filter either to specific or multiple
URL patterns
• <filter> and <filter-mapping> elements are used for configuring
filters
CODE SNIPPET
CONFIGURING FILTERS USING
ANNOTATIONS
• Configuration code can be directly included in the code of the
filter class
• @WebFilter – mark a filter
CODE SNIPPET
Creating a web
application using Filters
Creating a web application using Filters

More Related Content

What's hot (20)

Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
ASP.NET Basics
ASP.NET Basics ASP.NET Basics
ASP.NET Basics
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Json
JsonJson
Json
 
State management
State managementState management
State management
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
web communication protocols in IoT
web communication protocols in IoTweb communication protocols in IoT
web communication protocols in IoT
 
Network Layer by-adeel
Network Layer by-adeelNetwork Layer by-adeel
Network Layer by-adeel
 
Server Side Programming
Server Side ProgrammingServer Side Programming
Server Side Programming
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Java strings
Java   stringsJava   strings
Java strings
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 
Types of Drivers in JDBC
Types of Drivers in JDBCTypes of Drivers in JDBC
Types of Drivers in JDBC
 
Flow Control
Flow ControlFlow Control
Flow Control
 

Viewers also liked

Digikameran Kaytto Syksy2009
Digikameran Kaytto Syksy2009Digikameran Kaytto Syksy2009
Digikameran Kaytto Syksy2009Oulainen
 
Revised Linkedin Presentation 11 03 11
Revised Linkedin Presentation 11 03 11Revised Linkedin Presentation 11 03 11
Revised Linkedin Presentation 11 03 11bob_ministryatwork
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessionsvantinhkhuc
 
Căn hộ Quận 7, Belleza, 0989171123
Căn hộ Quận 7, Belleza, 0989171123Căn hộ Quận 7, Belleza, 0989171123
Căn hộ Quận 7, Belleza, 0989171123luongquocbao
 
01 session tracking
01   session tracking01   session tracking
01 session trackingdhrubo kayal
 

Viewers also liked (8)

Digikameran Kaytto Syksy2009
Digikameran Kaytto Syksy2009Digikameran Kaytto Syksy2009
Digikameran Kaytto Syksy2009
 
Url programming
Url programmingUrl programming
Url programming
 
Mathew 24
Mathew 24Mathew 24
Mathew 24
 
Revised Linkedin Presentation 11 03 11
Revised Linkedin Presentation 11 03 11Revised Linkedin Presentation 11 03 11
Revised Linkedin Presentation 11 03 11
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
 
Căn hộ Quận 7, Belleza, 0989171123
Căn hộ Quận 7, Belleza, 0989171123Căn hộ Quận 7, Belleza, 0989171123
Căn hộ Quận 7, Belleza, 0989171123
 
01 session tracking
01   session tracking01   session tracking
01 session tracking
 

Similar to Creating a web application using Filters

Advance java session 17
Advance java session 17Advance java session 17
Advance java session 17Smita B Kumar
 
Servlets - filter, listeners, wrapper, internationalization
Servlets -  filter, listeners, wrapper, internationalizationServlets -  filter, listeners, wrapper, internationalization
Servlets - filter, listeners, wrapper, internationalizationsusant sahu
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9aminmesbahi
 
How to get full power from WebApi
How to get full power from WebApiHow to get full power from WebApi
How to get full power from WebApiRaffaele Rialdi
 
Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programmingnibiganesh
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...WebStackAcademy
 
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, environmentjoearunraja2
 
Sling Component Filters in CQ5
Sling Component Filters in CQ5 Sling Component Filters in CQ5
Sling Component Filters in CQ5 connectwebex
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappersManolis Vavalis
 
SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4Ben Abdallah Helmi
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11Smita B Kumar
 
ASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdfASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdfsetit72024
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsPawanMM
 
Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6PawanMM
 

Similar to Creating a web application using Filters (20)

Advance java session 17
Advance java session 17Advance java session 17
Advance java session 17
 
Servlets - filter, listeners, wrapper, internationalization
Servlets -  filter, listeners, wrapper, internationalizationServlets -  filter, listeners, wrapper, internationalization
Servlets - filter, listeners, wrapper, internationalization
 
Servlet Filters
Servlet FiltersServlet Filters
Servlet Filters
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9
 
How to get full power from WebApi
How to get full power from WebApiHow to get full power from WebApi
How to get full power from WebApi
 
Advanced java programming
Advanced java programmingAdvanced java programming
Advanced java programming
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 9...
 
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
 
Sling Component Filters in CQ5
Sling Component Filters in CQ5 Sling Component Filters in CQ5
Sling Component Filters in CQ5
 
Servlet session 12
Servlet   session 12Servlet   session 12
Servlet session 12
 
Ch. 13 filters and wrappers
Ch. 13 filters and wrappersCh. 13 filters and wrappers
Ch. 13 filters and wrappers
 
SERVIET
SERVIETSERVIET
SERVIET
 
Servlet Filter
Servlet FilterServlet Filter
Servlet Filter
 
SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4SCWCD : The servlet container : CHAP : 4
SCWCD : The servlet container : CHAP : 4
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Advance java session 11
Advance java session 11Advance java session 11
Advance java session 11
 
VB.net&OOP.pptx
VB.net&OOP.pptxVB.net&OOP.pptx
VB.net&OOP.pptx
 
ASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdfASP.NET MVC_Routing_Authentication_Aurhorization.pdf
ASP.NET MVC_Routing_Authentication_Aurhorization.pdf
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
 
Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6
 

More from Soujanya V

Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysisSoujanya V
 
Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Soujanya V
 
Load balancing
Load balancingLoad balancing
Load balancingSoujanya V
 
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01Soujanya V
 
Implementing jsp tag extensions
Implementing jsp tag extensionsImplementing jsp tag extensions
Implementing jsp tag extensionsSoujanya V
 

More from Soujanya V (7)

Decision tree
Decision treeDecision tree
Decision tree
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2
 
Filter
FilterFilter
Filter
 
Load balancing
Load balancingLoad balancing
Load balancing
 
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
 
Implementing jsp tag extensions
Implementing jsp tag extensionsImplementing jsp tag extensions
Implementing jsp tag extensions
 

Recently uploaded

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 

Recently uploaded (20)

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 

Creating a web application using Filters

  • 2. WHAT IS FILTERS? • Java class that is called for responding to requests for resources(Servlet / JSP) • Dynamically change the behaviour of the resource • Intercept and process the requests • Process the responses after responses has been generated by servlet • Encapsulates and modifies values of request, response or header • Introduced in Servlet 2.3 specification
  • 3. EXPLORING THE NEED OF FILTERS • Suppose application is in the format of Excel. • At later point of time, clients may require it in another format like PDF, HTML etc. • Instead of modifying code every time, filter can be created to transform data dynamically in required formats.
  • 4. FEATURE AND UTILITY • Main feature : Reusabilty • Situations where filters are used: 1. Security verification 2. Logging operations 3. Session validation 4. Encryption
  • 5. EXPLORING THE WORKING OF FILTERS 1. When a request is sent for specific resource, request is intercepted by a filter. 2. To intercept a request, a filter should have access to HTTP request and response objects. 3. Objects are accessed by javax.servlet.ServletRequest and javax.servlet.ServletResponse objects 4. Needs to access the list of chained filters, which can accessed using javax.servlet.FilterChain object.
  • 6. EXPLORING FILTER API • The Filter API includes three interfaces: 1. Filter 2. FilterConfig 3. FilterChain
  • 7. FILTER INTERFACE • A Filter can be created in an application by implementing the javax.servlet.Filter interface. • Filter interface calls the following methods during life cycle of a filter: 1. Init() method 2. doFilter() method 3. Destroy() method
  • 8. THE Init() METHOD • Init() method is invoked by the web container only once when the filter is initialized. • Servlet container passes the FilterConfig object as a parameter through the init() method. Syntax: public void init(FilterConfig filterconfig) throws ServletException
  • 9. THE doFilter() METHOD • doFilter() method is invoked when a user requests a resource, such as a servlet to which the filter is mapped. • Syntax:public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws java.IOException,Servlet Exception.
  • 10. THE doFilter() METHOD doFilter() method can be implemented to perform the following tasks: • Examining the request. • Carrying out input filtering by wrapping the request object with filter content or headers. • Carrying out output filtering by wrapping the response object with filter content or headers. • Invoking the next filter in filter chain by calling the FilterChain object or blocking the request by not forwarding the request/response pair to next filter.
  • 11. destroy() METHOD • destroy() method is invoked when the filter instance is destroyed. • Once the destroy() method is called by the web container,the doFilter() method cannot be called again on this filter instance. • destroy() method enables to release any resources held by the filter.
  • 13. FILTERCONFIG INTERFACE • The FilterConfig interface used is stored the initialized data. • The init() method of the Filter interface takes a filter configuration object as an argument, which is an instance of FilterConfig interface. • The filter recieves filter configuration information during initialization from a servlet container through the FilterConfig object.
  • 14. METHODS OF FILTERCONFIG INTERFACE 1. getFilterName: • Returns the filter name as assigned in Deployment Descriptor. Syntax: public java.lang.String getFilterName() 2. getInitParameter: • Returns the named initialization parameter value as a string. • A null value is returned if the parameter is not found. • Syntax: Public java.lang.String getInitParameter(java.lang.String name)
  • 15. METHODS OF FILTERCONFIG INTERFACE 3. getInitParameterNames: • Returns an Enumeration of String objects. • An empty Enumeration is returned,if no initialization parameters are found for the filter. Syntax: public java.util.Enumeration getInitParameterNames(). 4. getServletContext: • Returns a reference of the ServletContext interface in which a filter is executed. Syntax: publicServletContext getServletContext()
  • 16. FILTERCHAIN INTERFACE • FilterChain interface provides a mechanism to invoke a series of filters,which are specified in filter chain,in an application. • If the invoked filter is the last one in chain,the target resource is invoked. • Syntax: • Public void doFilter(ServletRequest request,ServletResponse response) throws java.io.IOException,ServletException.
  • 17. CONFIGURING A FILTER • web.xml is used to configure filters to resources • Annotations- Servlet 3.0 • Deployment descriptor used for defining configuration and mapping for filters and servlets • Use of annotations eliminates the need of deployment descriptor
  • 18. CONFIGURING FILTERS USING DEPLOYMENT DESCRIPTOR • Deployment descriptor is located in WEB-INF directory of the web application. • Used to declare and map the filter either to specific or multiple URL patterns • <filter> and <filter-mapping> elements are used for configuring filters
  • 20. CONFIGURING FILTERS USING ANNOTATIONS • Configuration code can be directly included in the code of the filter class • @WebFilter – mark a filter
  • 22. Creating a web application using Filters