What is the use of filter and chain in servlet?

后端 未结 3 1343
名媛妹妹
名媛妹妹 2020-11-27 18:49

chain.doFilter(req,res);
We used this in a servlet program. I want to know what is the use of the method doFilter() in a servlet? Also what is

3条回答
  •  醉酒成梦
    2020-11-27 18:53

    What are Filters ?

    Filters are used to intercept and process requests before they are sent to servlets(in case of request) .

    OR

    Filters are used to intercept and process a response before they are sent back to client by a servlet.

    Why they are used ?

    -Filters can perform security checks.

    -Compress the response stream.

    -Create a different response.

    What does doFilter() do ?

    The doFilter() is called every time the container determines that the filter should be applied to a page.

    It takes three arguments

    ->ServletRequest

    ->ServlerResponse

    ->FilterChain

    All the functionality that your filter supposed to do is implemented inside doFilter() method.

    What is FilterChain ?

    Your filters do not know anything about the other filters and servlet. FilterChain knows the order of the invocation of filters and driven by the filter elements you defined in the DD.

提交回复
热议问题