Filter application scenarios

Filter application scenario
by understanding filter filters, that can be treated can be done in the following three cases:

1> through the control of the call to the method chain.doFilter to decide whether to access the target resources.
For example, you can verify the user rights and so on.
Determine whether the user has permission to access certain resources have permission to release, did not execute permissions chain.doFilter method.


2> by before calling chain.doFilter method to do processing to achieve certain objectives.
For example, to solve the problem of Chinese garbled and so on. Before the method can doFilter,
performing setup request and response coding. Encapsulation of decorative can even request interface to handle Chinese garbled embodiment of the get request (request to rewrite the corresponding.
The getParameter method).

3> through after calling chain.doFilter method, do some processing to achieve certain objectives.
For example, the entire web site is compressed.
Encapsulation of the response object class A decorative chain.doFilter before calling method, rewriting and rewriting getWriter getOutputStream methods.
Within the class A, the contents of the cache into the output stream ByteArrayOutputStream, then, after performing chain.doFilter method,
obtaining the A class ByteArrayOutputStream stream buffer data, with GZIPOutputStream compressed stream.

Guess you like

Origin blog.csdn.net/qq_37807989/article/details/89076267