I just started with Spring Web MVC. I\'m trying to avoid file extenstions in the url. How can i do this? (I\'m using Spring 2.5.x)
Bean:
<
In 3.0, / seems to work. That is...
<url-pattern>/</url-pattern>
Try first:
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
If that doesn't work then problem is somewhere else. Is your Apache set up to forward those urls to Tomcat? Something like:
JkMount /hello worker1
Have you tried <url-pattern>/*</url-pattern>
in the servlet mapping and <bean name="/hello" .../>
?
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Then you need to register your urls to be handled by a particular controller. See the following
http://static.springsource.org/spring/docs/2.0.x/reference/mvc.html
As far as I know you can't do this if you're using JSP's as your view for controllers.
Because when you pass a model to a JSP, Spring MVC internally performs a 'forward' to the URL of the JSP. If you use <url-pattern>/*</url-pattern>
then this forward will also be handled by your DispatcherServlet and not by your JSP view.
What you can do is use <url-pattern>/something</url-pattern>
and have your JSP's in a different directory
In Spring 3.2 at least, the accepted answer above is very nearly but not quite what's needed. The web.xml bit below just worked for me, and I'm adding it to the thread here for reference of whoever googles this next...
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>