Spring Mapping MVC url patterns in web.xml?

I have below config in web.xml

<servlet>  
        <servlet-name>mvc-dispatcher</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring/mvc-dispatcher-servlet.xml</param-value>
         </init-param>  
        <load-on-startup>1</load-on-startup>  
    </servlet>

    <servlet-mapping>  
        <servlet-name>mvc-dispatcher</servlet-name>  
        <url-pattern>*.do</url-pattern>  
    </servlet-mapping>

      

I have a controller as shown below.

@Controller  
public class SomeController { 

   @RequestMapping("/somePath")
    public String showExtendedUi() {
        return "somePage";
    }


}  

      

The client will now call the controller by sending url parameters as belo:

http://localhost:8080/myApp/somePath?param1=456&param2=456

      

But the controller method is not called.

Is my URL correct?

+2


source to share


2 answers


Your controller method is not being called because you mapped mvc-dispatcher

in *.do

Change Servlet Mapping to



<servlet-mapping>  
        <servlet-name>mvc-dispatcher</servlet-name>  
        <url-pattern>/</url-pattern>  
    </servlet-mapping>

      

+6


source


Since the URL pattern for the dispatcher servlet is set to * .do, the controller will only be called on the URLs of the โ€œsomething.doโ€ pattern.



so your url http://localhost:8080/myApp/somePath.do?param1=456&param2=456

will work if all other configurations are done correctly.

+2


source







All Articles