Pr.Pg Next Pg

Filters in jsp tutorials

  • Filters can intercept the request and also control the response all without the servlet knowing, which means that filters can be used without touching the servlets code, filters can be a very powerful tool.

  • Filters are Java components very similar to servlets and JSP that you can use to intercept and process

  • requests before that are sent to the servlet, or to process responses after the servlet has completed, but before the response goes back to the client.

  • The Container decides when to invoke your filters based on the declarations in the web.xml file, the web.xml file maps which filters will be called for which request URL patterns.

  • Below are the thing that can be done with the help of filters

    1. Perform security checks (request)

    2. Reformat request headers or bodies (request)

    3. Audit or log requests (request)

    4. Compress the response stream (response), I have an example of this below

    5. Append or alter the response stream (response)

    6. Create a different response altogether (response)

Pr.Pg border                                              Next Pg