2

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 controller as below.

@Controller  
public class SomeController { 

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


}  

Now client would call the controller by sending url params as belo:

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

But the controller method is not being called.

Is my URL correct?

2 Answers 2

6

Your controller method is not being invoked because you have mapped mvc-dispatcher to *.do Change servlet mapping to

<servlet-mapping>  
        <servlet-name>mvc-dispatcher</servlet-name>  
        <url-pattern>/</url-pattern>  
    </servlet-mapping>
Sign up to request clarification or add additional context in comments.

2 Comments

Or change the annotation and url to @RequestMapping("/somePath.do") of course. In any case the configuration needs to made so the rules don't conflict with each other.
If config /, then will static resource like image / js / css also been get by springMVC dispatcher ?
2

As the URL pattern for Dispatcher Servlet is configured as *.do, The controller would be called only only by url requests of pattern "something.do".

so your url http://localhost:8080/myApp/somePath.do?param1=456&param2=456 would work if all other configurations are made properly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.