Announcement Announcement Module
Collapse
No announcement yet.
Problems mapping DispatcherServlet with "/*" url p Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems mapping DispatcherServlet with "/*" url p

    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

  • #2
    I think it is possible to create a filter that extends org.springframework.web.filter.OncePerRequestFilte r. The filter can get access to Spring contexts using org.springframework.web.context.support.WebApplica tionContextUtils, checks the request against your database, and then dispatchs the request to Spring Dispatcher. This way, you do not need to change the url-pattern for DispatcherServlet.

    Comment


    • #3
      Hi did you find a solution for that?

      Hi did you find a solution for that?
      Thanks

      Originally posted by scott69taylor View Post
      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

      Comment

      Working...
      X