0

I am trying a sample spring MVC application. My web.xml has

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>        
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/test</url-pattern>
</servlet-mapping> 

so my question is how I can call my test controller if I just type in the url

   http://localhost:8080/MySpringProject/test 

Where do i need to make change to call exactly this type of URL so that my test controller called. I don't know what I am asking is correct or not but my requirement is that I don't want to end my UrL with "/" or "test.htm".

Please help and thanks in advance

Harry
  • 4,705
  • 17
  • 73
  • 101

1 Answers1

4

You usually map your dispatcher servlet to /, and then you have controllers with @RequestMapping("/foo/bar"). But if you define a servlet with a more specific url, it will get picked up.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Hi Bozho, so if I have mapping like @RequestMapping("/test") in my controller then with this http://localhost:8080/MySpringProject/test URL this should work? – Harry Jan 08 '12 at 22:20
  • According to this answer http://stackoverflow.com/questions/3878957/basic-spring-mvc-config-pagenotfound-using-internalresourceviewresolver, this will prevent one from hiding your view jsps in the WEB-INF/ folder. In your app, do you configure the InternalResourceViewResolver to point to a prefix in the "WEB-INF" folder. – onejigtwojig Sep 04 '12 at 04:50