Results 1 to 2 of 2

Thread: Spring 3.2.0, path variables, url-patterns for dispatcher servlet question

  1. #1
    Join Date
    Feb 2009
    Location
    hbg, pa
    Posts
    7

    Default Spring 3.2.0, path variables, url-patterns for dispatcher servlet question

    I've been reading through the Pro Spring MVC with WebFlow book and it uses a Servlet 3.0 container and maps a dispatcher servlet with a mapping of *.htm. Later, they change this to / (which I didn't notice). I was trying to run a page that expected to see /book/detail/#, where the number was the book's pk. The problem was, my URL was formed as /book/detail.htm/#, and this was not being handled by the dispatcher.

    I guess my questions are:
    1. In order to use these path variables, are we required to map the dispatcher to / ?
    2. If we map it to /, then all resources go through the dispatcher. Is that the reasoning then for adding a resource handler in the configuration, i.e.

    Code:
        @Override
        public void addResourceHandlers(final ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/resources/**/*").addResourceLocations("classpath:/META-INF/web-resources/");
        }
    Just trying to get a handle on how these requests should be mapped. The real issue for me with this book is that it is based on Servlet 3.0 and I have a Servlet 2.5 Production environment, which appears that they touch on, briefly at page 539 (deploying to Tomcat 6/Cloud Foundry).

    Thanks for any and all feedback.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    [quote]
    1. In order to use these path variables, are we required to map the dispatcher to / ?
    [quote]
    No you can map it to whatever you like but to achieve nice URLs in general you use / as the mapping.

    2. If we map it to /, then all resources go through the dispatcher. Is that the reasoning then for adding a resource handler in the configuration, i.e.
    No... This is for handling static content.

    There is also a configureDefaultServletHandling which can be overriden to enable the default-servlet again (it basically passes on the request to the default-servlet if it cannot be handled by the DispatcherServlet).

    maps a dispatcher servlet with a mapping of *.htm. Later, they change this to / (which I didn't notice).
    This might be an oversight when writing the chapters but after so many rounds of revisions you start to read over those pesky things. Sorry for the inconvenience (you could write a note to the publisher so that we might be able to get it right in a next revision of the book).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •