Announcement Announcement Module
Collapse
No announcement yet.
SimpleUrlHandlerMapping: mapping urls without suffix Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleUrlHandlerMapping: mapping urls without suffix

    Hi!

    I'm "porting" an existing servlet to spring. This app have urls like /myapp/show/aaa/bbb/ccc where "/aaa/bbb/ccc" is info that should be passed to the application.

    In myapp-servlet.xml I have tried with lots of different stuff f.x. the following:


    Code:
    <bean id="urlMapping"  class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
           <property name="mappings">
                <props>
                    <prop key="/show/**">showController</prop>
                </props>
            </property> 
     </bean>
    This works fine with the url http://myhost/myapp/show

    but I add something at the end of the url like

    http://myhost/myapp/show/

    or

    http://myhost/myapp/show/aaa

    I get 404 page and and warning like

    WARN 15.10 20:47:04 (DispatcherServlet.java:501) - No mapping for [/myapp/show/] in DispatcherServlet with name 'myapp'

    Any ideas how to get the DispatcherServlet to see those to last urls?




    -Kaj

  • #2
    Hi,
    Could you try key="show/**/*" ?

    Olivier

    Comment


    • #3
      Originally posted by ojolly
      Hi,
      Could you try key="show/**/*" ?

      Olivier
      Thank you for answering!

      When using

      <prop key="show/**/*">showController</prop>

      both.../show, .../show/, .../show/something and .../show/something/ gives 404 and messages like the one bellow in the log:

      WARN 16.10 16:01:10 (DispatcherServlet.java:501) - No mapping for [/myapp/show] in DispatcherServlet with name 'myapp'


      Any ideas?


      -Kaj

      Comment


      • #4
        Looking at the code, it seems that show/** or /show/** should do the trick.
        Can you dump the servlet configuration of your web.xml ?
        By the time, I'll try to reproduce your exact setup...

        Olivier

        Comment


        • #5
          Originally posted by ojolly
          Looking at the code, it seems that show/** or /show/** should do the trick.
          Can you dump the servlet configuration of your web.xml ?
          By the time, I'll try to reproduce your exact setup...

          Great! Thank you for taking time to look at this issue!

          I have made my web.xml and myapp-servlet.xml available at http://folk.uio.no/kajh/tmp/springurl/

          It is actualy "forside" instead of "show".
          ("forside" = frontpage in Norwegian Just fyi.


          -Kaj

          Comment


          • #6
            It appears that, by default, internally a path like /show/bla/aaa/bbb/ccc will be canonized into /ccc before being checked against /show/** hence the issue.

            If you want the full path to be checked against your expression, configure your resolver by setting alwaysUseFullPath to true, like this :

            Code:
            	<bean id="urlMapper"
            		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            		<property name="mappings">
            			<props>
            				<prop key="/show/**">basicController</prop>
            			</props>
            		</property>
            		<property name="alwaysUseFullPath">
            			<value>true</value>
            		</property>
            	</bean>
            That should do the trick

            Regards

            Olivier

            Comment


            • #7
              Originally posted by ojolly
              Code:
              	<bean id="urlMapper"
              		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
              		<property name="mappings">
              			<props>
              				<prop key="/show/**">basicController</prop>
              			</props>
              		</property>
              		<property name="alwaysUseFullPath">
              			<value>true</value>
              		</property>
              	</bean>
              That should do the trick

              It did Now the urlmapping works just perfect!

              Thank you for helping us with this issue!


              -Kaj

              Comment


              • #8
                Just fyi:

                I noticed I couldn't find any info about alwaysUseFullPath in the spring documentation so I created the following issue in jira

                http://opensource.atlassian.com/proj...browse/SPR-402


                -Kaj

                Comment


                • #9
                  However, it is available in the api, http://www.springframework.org/docs/...erMapping.html
                  coming from http://www.springframework.org/docs/...lPath(boolean)

                  Olivier

                  Comment


                  • #10
                    URL mapping canonical form

                    On Sat Oct 16, 2004 12:40 pm, ojolly wrote:

                    "It appears that, by default, internally a path like /show/bla/aaa/bbb/ccc will be canonized into /ccc before being checked against /show/** hence the issue."

                    I must confess, that even with some experience in this area, I find the topic URL pattern mapping somewhat confusing.

                    kajh's web.xml had the following servlet mappings:
                    - <servlet-mapping>
                    <servlet-name>springhoudini</servlet-name>
                    <url-pattern>/forside/*</url-pattern>
                    </servlet-mapping>
                    - <servlet-mapping>
                    <servlet-name>springhoudini</servlet-name>
                    <url-pattern>/vis/*</url-pattern>
                    </servlet-mapping>

                    My interpretation is that these correspond to /show/* at the servlet mapping level.

                    Why is it that /show/bla/aaa/bbb/ccc can then be canonized down to /ccc?
                    I guess this would make more sense to me if the servlet mapping was /show/bla/aaa/bbb/*, for I sort of assumed that what you meant was that the handler mapping was *relative* to the servlet mapping. But that doesn't seem to be what you are saying.

                    Could someone please help me understand the relationship between the servlet mapping and the handler mapping? I am now more certain than ever that I have a murky-at-best understanding of how this is supposed to work.

                    Comment


                    • #11
                      Mapping url with anchor name tag at the end

                      Hello,

                      Given that this post is from 2004, I thought it'd be fine if I bumped it back up with a related question.

                      I'm trying to do the following mapping:

                      Code:
                      <prop key="**/secure/admin/ManageResourceProperty.do*">ManageResourceProperty</prop>
                      Because I want to be able to have a named anchor tag at the end of that URL, for example, I could be on a page, and click a link that looks like the following:

                      HTML Code:
                      <a href="ManageResourceProperty.do#topOfComponent">New Resource Property</a>
                      But trying that, when I click on it, nothing happens. It's not even making a call to that Controller at all... so I imagine the UrlMapping isn't parsing it as something it understands...

                      I tried the property alwaysUseFullPath suggested in this thread, but it didn't do anything for me...

                      Any thoughts?

                      Note: there is an anchor defined on the View of the ManageResourceProperty controller with the name topOfComponent as follows:

                      HTML Code:
                      <a name="topOfComponent"/>
                      Last edited by saadnabs; Jul 7th, 2008, 10:08 AM. Reason: To add a note..

                      Comment

                      Working...
                      X