Spring Controller's URL request mapping not working as expected

Posted by Atharva on Stack Overflow See other posts from Stack Overflow or by Atharva
Published on 2012-06-26T08:58:21Z Indexed on 2012/06/26 9:15 UTC
Read the original article Hit count: 184

I have created a mapping in web.xml something like this:

<servlet>  
        <servlet-name>dispatcher</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <load-on-startup>1</load-on-startup>  
</servlet>
<servlet-mapping>  
        <servlet-name>dispatcher</servlet-name>  
        <url-pattern>/about/*</url-pattern>  
</servlet-mapping>

In my controller I have something like this:

import org.springframework.stereotype.Controller;  
@Controller  
public class MyController{  
    @RequestMapping(value="/about/us", method=RequestMethod.GET)
    public ModelAndView myMethod1(ModelMap model){  
        //some code  
        return new ModelAndView("aboutus1.jsp",model);  
    }  
    @RequestMapping(value="/about", method=RequestMethod.GET)
    public ModelAndView myMethod2(ModelMap model){  
        //some code  
        return new ModelAndView("aboutus2.jsp",model);  
    }  
}

And my dispatcher-servlet.xml has view resolver like:

<mvc:annotation-driven/>  
<bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:viewClass="org.springframework.web.servlet.view.JstlView"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp"/>

To my surprise: request .../about/us is not reaching to myMethod1 in the controller. The browser shows 404 error. I put a logger inside the method but it isn't printing anything, meaning, its not being executed.
.../about works fine! What can be the done to make .../about/us request work? Any suggestions?

© Stack Overflow or respective owner

Related posts about mvc

Related posts about spring-mvc