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:
<bean name="/hello.htm" class="springapp.web.HelloController"/>
I want it to be:
<bean name="/hello" class="springapp.web.HelloController"/>
I cannot get it to work. Any ideas?
Edit:
Url-mapping
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
I have tried changing the url-pattern with no luck (* and /*).
In 3.0, / seems to work. That is...
<url-pattern>/</url-pattern>
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
<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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With