Results 1 to 2 of 2

Thread: URL mapping issues when URL has a trailing slash

  1. #1
    Join Date
    Mar 2011
    Posts
    1

    Default URL mapping issues when URL has a trailing slash

    I'm testing an upgrade from Spring 2.0 to Spring 3.0.5 on Tomcat and am having an issue where there is different mapping behavior for URLs that have a trailing slash versus an identical URL without the trailing slash.

    For example, in my Spring 2.0 implementation, the following URLs would both map to the same controller class, per the Spring MVC XML configuration below:

    • /search/categories
    • /search/categories/


    Code:
    <bean id="searchMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="order" value="1"/>
        <property name="mappings">
            <props>
                <prop key="/search/categories">categoriesController</prop>
            </props>
        </property>
    </bean>
    However, in Spring 3.0.5, /search/categories/ (note trailing slash) is not mapped to the controller. Only /search/categories (no trailing slash) gets mapped.

    I know that the XML configuration is deprecated going forward and, unfortunately, I'm unable to move off of it just yet. But I am unsure as to why with Spring 3.0.5 there is new behavior for URLs with trailing slashes. Any suggestions or thoughts on a possible fix? Will I need to go as far as implementing an Apache Rewrite condition to remove trailing slashes on URLs?

    Thanks for your help!
    Michael

  2. #2
    Join Date
    Mar 2011
    Posts
    1

    Default

    Possibly simple workaround. Could you add another key for the trailing slash? This is almost redundant code but it might work. I don't have enough info to help any further, but this might be nicer than a redirect if it works. Perhaps they wanted the mappings to be more specific in 3.0?

    Code:
    <bean id="searchMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="order" value="1"/>
        <property name="mappings">
            <props>
                <prop key="/search/categories">categoriesController</prop>
                <prop key="/search/categories/">categoriesController</prop>
            </props>
        </property>
    </bean>

Tags for this Thread

Posting Permissions

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