• Filters are used to pre process the request and post process the response.
  • This concept has introduced in servlet 2.3 version.
  • Preprocessing involves authentication , logging ,authorization , change request information.
  • Post processing involves encrypting response compressing response.
Filters in java



Application areas of Filter:

  • To implement logging mechanism.
  • To perform authentication.
  • To perform authorization.
  • To alter request information.
  • To alter response information.
  • Encrypting response.
  • Compressing response.

Interfaces present in Filter API: 

  • Javax.servlet.Filter
  • Javax.servlet.FilterConfig
  • Javax.servlet.FilterChain

 Filter:

  • Every filter class should implement filter interface either directly or indirectly.
  • Filter interface defines the most common which can be applicable for any Filter object.
  • Filter interface defines following methods
    1. init()
    2. doFilter()
    3. destroy()

  • public abstract void init(FilterConfig config) Throws ServletException:
    This method is used to perform initialization activities.
    This method will be executed just after filter object is created.
  • public abstract void doFiletr(ServletRequest req, ServletResponse res, FilterChain ch) throws
    IOException, ServletException
    .
    This method will be executed for every request to perform filter activities.
    In this method only we have to implement entire Filter logic
    This method takes filterChain object as argument and by using that we can forward the request
    to the nest level. Next level can be again filter or servlet.
  • public abstract void destrroy();
    this method will be executed only once to perform cleanup activities just before taking filter from out of service .





Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu