
Originally Posted by
scott69taylor
I want to create a webapplication which examines the url for every external http request, and then compares that url to a list of urls in a database table. If a match is found in the database an appropriate ModelAndView is returned.
The problem is how do I configure the DispatcherServlet in the web.xml file so that it gets a chance to examine every incoming request? If I specify "/*" as the url-pattern in the servlet mapping then I end up with an infinite loop. I haven't looked at the code, but presumably when my Controller returns a ModelAndView, Spring does a dispatch and because of the mapping the same DispatcherServlet get calls.
Note I really don't want to have to limit myself to urls that begin with a specific prefix, or end with a specific postfix (eg. .do). That's one of the major objectives of the web application.
While the problem isn't completely Spring specific, its made more difficult by the fact that Spring's web framework provides a DispatcherServlet rather than a DispatcherServletFilter. If Spring provided a DispatcherServletFilter it would be fairly trivial since servlet filter mappings can be specified for incoming urls only (and not when dispatching).
Does anyone have an elegant way to fix the infinite loop problem? The only idea I have so far is to specify the servlet mapping for the ServletDispatcher using a url-pattern like "/myprefix/*", and then create a ServletFilter with a url mapping of "/*". The servlet filter would basically extract the incoming url, preappend the "/myprefix" prefix and use the resulting string to dispatch the request to Spring Dispatcher. Kinda of ugly, but it might work.
I'm fairly new to Spring MVC, so I'm hoping there is a better way. Any other ideas would be greatly appreciated.
/Scott