Session 3 inter-servlet communication & filters - Giáo trình Bách Khoa Aptech

1,084 views
987 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,084
On SlideShare
0
From Embeds
0
Number of Embeds
564
Actions
Shares
0
Downloads
50
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Session 3 inter-servlet communication & filters - Giáo trình Bách Khoa Aptech

  1. 1. Slide 1 of 25 Filters Inter-Servlet Communication
  2. 2. Slide 2 of 25 Objectives  Introduction to Filters  Filter API  Configuring Filter  Manipulating Request and Responses  Servlet Communication
  3. 3. Slide 3 of 25 Introduction Filter
  4. 4. Slide 4 of 25 Filters  Components that add functionality to the request and response processing of a Web Application  Intercept the requests and responses that flow between a client and a Servlet/JSP.
  5. 5. Slide 5 of 25 Filter Participation User Filter Web Resource (Servlet / JSP) Request Response Filter Participating in Request-Response Process
  6. 6. Slide 6 of 25 Filter Life Cycle Instantiation and Loading Initialization init() doFilter() destroy() Unavailable GC
  7. 7. Slide 7 of 25 Filter Chain  Invoke a series of filters  If the Calling filter is last filter, will invoke web resource Filter 1 Client Filter 2 Filter 3 Web Resourc e Working of Filter Chain Filter Chain
  8. 8. Slide 8 of 25 Usage of Filter  Authentication  Logging and auditing filter  Image conversion filters  Data compression  Encryption filters  Filters that trigger resource access events
  9. 9. Slide 9 of 25 Benefits of Filter
  10. 10. Slide 10 of 25 Compress Filter
  11. 11. Slide 11 of 25 Working of Filter
  12. 12. Slide 12 of 25 Working of Filter
  13. 13. Slide 13 of 25 Filter API
  14. 14. Slide 14 of 25 “Filter” Interface A filter is an object than perform filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.  Init()  doFilter()  Destroy()
  15. 15. Slide 15 of 25 “FilterConfig” Interface  A filter configuration object used by a servlet container used to pass information to a filter during initialization  Methods – getFilterName() – getInitParameter() – getInitParameterNames() – getServletContext()
  16. 16. Slide 16 of 25 “FilterChain” Interface  A FilterChain is an object provided by the servlet container to the developer giving a view into the invocation chain of a filtered request for a resource  Methods – doFilter()
  17. 17. Slide 17 of 25 Configuring Filter <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <filter> <filter-name>TimerFilter</filter-name> <filter-class>filters.TimerFilter</filter-class> </filter> <filter-mapping> <filter-name>TimerFilter</filter-name> <url-pattern>/TimerFilter</url-pattern> </filter-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>Timer.html</welcome-file> </welcome-file-list> </web-app> 17
  18. 18. Slide 18 of 25 Filter Element  <icon>  <filter-name>  <display-name>  <description>  <filter-class>  <init-param>
  19. 19. Slide 19 of 25 Filter-Mapping Element  <filter-name>  <url-name>  <servlet-name>
  20. 20. Slide 20 of 25 Configuring Filter Chain
  21. 21. Slide 21 of 25 Manipulating Request and Response
  22. 22. Slide 22 of 25 Manipulating Request and Response  ServletRequestWrapper  ServletResponseWrapper
  23. 23. Slide 23 of 25 Inter-Servlet Communication  A process where two or more Servlets communicates with each other to process the client request.  A Servlet can forward the request to another Servlet to process the client request.  A Servlet can include the output of another Servlet to process the client request.
  24. 24. Slide 24 of 25 Applet – Servlet Communication  Developing Applet front end application  Establishing connection between applet and servlet  Communicasting throught object serialisation  Sending objects from applet to servlet  Sending objects from servlet to applet
  25. 25. Slide 25 of 25 Summary  Introduction to Filters  Filter API  Configuring Filter  Manipulating Request and Responses  Servlet Communication

×