Spring Controller's URL request mapping not working as expected

旧街凉风 提交于 2019-12-04 07:34:48
Ravi Khakhkhar

You need to use @RequestMapping(value="/us", method=RequestMethod.GET) or you need to request about/about/us

ravi ranjan

Since you have mapped "/about" in your web.xml, the url it will pass will be like this www.xyz.com/about/*

As your configuration says it will work for

  1. www.xyz.com/about/about/us
  2. www.xyz.com/about/about

In order to to work properly either use /* in web.xml instead of /about

or change the controller's endpoint to

@RequestMapping(value="/us", method=RequestMethod.GET)

@RequestMapping(value="/", method=RequestMethod.GET)

Okay I got the thing working, here are things I added in the dispatcher-servlet.xml:

<bean
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="alwaysUseFullPath" value="true" />
    </bean>

    <bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="alwaysUseFullPath" value="true" />
</bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!