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

2
  • What controller? All you have is a DispatcherServlet. Commented Jan 8, 2012 at 22:09
  • Hi skaffman, in controller I have mapping like @RequestMapping("/test"). Is this should work? I myself is confused Commented Jan 8, 2012 at 22:18

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Bozho, so if I have mapping like @RequestMapping("/test") in my controller then with this localhost:8080/MySpringProject/test URL this should work?
According to this answer stackoverflow.com/questions/3878957/…, 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.

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.