i am trying to create and run a simple Spring 3.1 mvc web application where i have defined a controller that simply returns \"hello\" in the response body using the class be
Your DispatcherServlet
is mapped to *.htm
:
<servlet-mapping>
<servlet-name>FreedomSpring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
But you are accessing the controller through non-matching URL: http://localhost:8080/FreedomSpring/hello. You have three choices:
Change you dispatcher servlet to:
<servlet-mapping>
<servlet-name>FreedomSpring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
but in this case all requests will be handled through the Spring MVC, including images and other static resources
Use extension in controllers as well:
<url-pattern>/*.htm</url-pattern>
and map Hello
controller to .htm
so that you use: http://localhost:8080/FreedomSpring/hello.htm.
Map controllers to a different subdirectory:
<url-pattern>/mvc/*</url-pattern>
to access them you will have to use: http://localhost:8080/FreedomSpring/mvc/hello without making any changes to the controller itself.