difference between a valve and a filter
Can someone explain the difference between a servlet filter and tomcat valve. What is the advantage of using one over the ot开发者_如何学运维her?
From Tomcat documentation:
A Valve element represents a component that will be inserted into the request processing pipeline for the associated Catalina container
The servlet filters serve the exact same purpose, but valves are Tomcat's specific classes, tightly coupled to Tomcat infrastructure/API. On the other hand servlet API is implemented by all compatible web containers. That said, valves won't work with e.g. Jetty, which has different API for that, while servlet filters will.
The other important difference is that valves are working on container level (intercepting all applications/requests), while servlet filters are intercepting all request only to a given application. So if you want to implement server-wide interceptor, valves are necessary.
Valves are tomcat-specific. Filters are standard and their behaviour is defined by the specification. In most cases you would want a filter.
Valves are to be used only for functionalities that requrie access to native-tomcat APIs. Which is rather rare.
Not exactly right. With filters you can affect some pieces of applications, engines or host, with url-pattern. Valves only affect all the pieces of an application, engines or host. Valves have no url-pattern. That´s all.
精彩评论