Java Filter URL pattern specific to request params

后端 未结 2 1848
广开言路
广开言路 2020-12-10 09:07

We have a situation where we want to use filter for URL\'s containing some specific request parameters, e.g:

http://mydomain.com/?id=78&formtype=simple_form&.....         


        
2条回答
  •  感动是毒
    2020-12-10 10:06

    You must parse the URL params in the body of the filter, not in web.xml;

    I made such a thing, but I used a phase listener, a configuration entry (in a configuration file) that mapped URL params to FQN of classes that handle a particular "action" (by action I mean a URL param from a GET/POST); than, the phase listener would parse all the URL params from each GET/POST and send each of them to a Dispatcher. The Dispatcher's job is to call the right handler (singleton object corresponding to the FQN for that URL param). The handler then just does the specific thing with the URL value he receives.

    The same thing can be made by using a filter instead of phase listener.

提交回复
热议问题