Hi all,
First off, if this is a duplicate, I apologize. I did quite a bit of searching but couldn't find much and I suspect I wasn't using the right terms...
I'm building a site with Spring MVC and using the annotation-driven configuration. What I'd like to do is have urls that do not have any extension at the end (.html, .do, etc). So they would look like http://www.mysite.com/account/create
which I know is something that is traditionally accomplished using mod_rewrite
on Apache or using files without extensions. It seems as though it could be done without using a rewrite engine (I know about the urlrewritefilter project) as Spring has support for pulling parameters out of the request string (See section 15.3.2.1 of the documentation) and the pet store example doesn't appear to have extensions at the end of its urls.
However, it seems as though whenever I attempt to forward all requests to the dispatcher servlet (my thinking for how to negate the need for something like *.htm
), I run into trouble...I'm able to get it work (using XML configuration, I recently switched to annotation configuration) using just a standard "*.htm" for all of the pages.
My controller code looks like
@Controller
@RequestMapping("/home")
public class HomeController {
...
@RequestMapping(method = RequestMethod.GET)
public ModelAndView get() {
...
}
And my web.xml looks like
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatch</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Am I missing something here? Is this possible without using a rewrite engine?
I should note, the above configuration doesn't work. It always returns a 404
error...