How to add filters to servlet without modifying web.xml

后端 未结 3 428
醉话见心
醉话见心 2020-12-07 15:24

I\'d like the ability to modify/configure filters in a different way than web.xml. Here is a static configuration of 2 filters. I\'d like the ability to have one filter stat

3条回答
  •  暖寄归人
    2020-12-07 15:51

    It can be achieved in easy steps, even for pre-3.0 Servlet spec:

    1. Add a filter containing a static & ordered collection of Classes (chain).
    2. Map the filter to intercept every traffic.
    3. Manipulate the order & existence of your helper classes (those will be called privately by your filter upon interception of traffic) in the chain.

    Ref: Xstream uses same kind of pattern for Serializer, well not with Servlet/Filter though. :)

提交回复
热议问题