Spring Displaying a controller url request does not work properly

I 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 looks like a resolving kind, for example:

<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, the request .../about/usdoes not reach myMethod1 in the controller. Error 404 is displayed in the browser. I place the logger inside the method, but it does not print anything, which means that it does not execute.
.../aboutworks great! What can be done to make the request .../about/uswork? Any suggestions?

+5
source share
3 answers

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

+12
source

"/about" web.xml, URL-, , : www.xyz.com/about/*

,

  • www.xyz.com/about/about/us
  • www.xyz.com/about/about

, /* web.xml /about

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

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

+2

Ok, I did it, here's what I added to 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>
-3
source

All Articles