session 3 inter-servlet communication & filters - giáo trình bách khoa aptech

25
Slide 1 of 25 Filters Inter-Servlet Communication

Upload: hoc-lap-trinh-web

Post on 30-Nov-2014

1.121 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

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

Slide 1 of 25

Filters Inter-Servlet Communication

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

Slide 2 of 25

Objectives Introduction to Filters Filter API Configuring Filter Manipulating Request and Responses Servlet Communication

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

Slide 3 of 25

Introduction Filter

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

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.

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

Slide 5 of 25

Filter Participation

User FilterWeb Resource(Servlet / JSP)

Request

Response

Filter Participating in Request-Response Process

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

Slide 6 of 25

Filter Life CycleInstantiation and Loading

Initialization init()

doFilter()

destroy()

Unavailable GC

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

Slide 7 of 25

Filter Chain Invoke a series of filters If the Calling filter is last filter, will invoke web resource

Filter 1

ClientFilter

2Filter

3

Web Resourc

e

Working of Filter Chain

Filter Chain

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

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

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

Slide 9 of 25

Benefits of Filter

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

Slide 10 of 25

Compress Filter

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

Slide 11 of 25

Working of Filter

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

Slide 12 of 25

Working of Filter

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

Slide 13 of 25

Filter API

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

Slide 14 of 25

“Filter” InterfaceA 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()

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

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()

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

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()

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

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

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

Slide 18 of 25

Filter Element <icon> <filter-name> <display-name> <description> <filter-class> <init-param>

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

Slide 19 of 25

Filter-Mapping Element <filter-name> <url-name> <servlet-name>

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

Slide 20 of 25

Configuring Filter Chain

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

Slide 21 of 25

Manipulating Request and Response

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

Slide 22 of 25

Manipulating Request and Response

ServletRequestWrapper ServletResponseWrapper

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

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.

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

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

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

Slide 25 of 25

Summary Introduction to Filters Filter API Configuring Filter Manipulating Request and Responses Servlet Communication