Filters are like servlets. There exists many servlet container.Do filters take the role in servlet container only?
I read everytime Filters开发者_如何学C are like servlets. Resin is a servlet container. Is there exist any filter container to initialize filters or does it take the role in servlet container only. Can anybody elaborate how it works?
- Servlets are components that handle an HTTP request/response cycle
- Filters are components that intercept HTTP requests and response before/after they reach the target servlet
- Servlet containers make sure the two points above work - i.e. they instantiate servlets and filters and "give" them the requests/responses
There is nothing like Filter container, it is included in servlet container.
Java Servlet Filters allow you to "layer on" additional behavior in front of a Servlet, JSP page, or even static resources like css, js, and image files.
The classic example of Filter use is Authorization: checking to ensure the user is authorized to view the specified resource.
Some observations:
- A Filter can do work before the specified resource (servlet, etc.), after, or both
- Multiple Filters may be applied to the same resource
精彩评论