我正在嘗試使用SpringMVC創建一個簡單的應用程序用於學習目的。我想爲各種動作的URL這種格式如何在SpringMVC中使用@RequestMapping實現特定的url格式
http://localhost:8080/appname/controllername/actionname.html
的servlet的映射裏指定DispatcherServlet的URL模式是
<url-pattern>*.html</url-pattern>
這裏是我的ContactController中
方法之一@RequestMapping("list.html")
public ModelAndView showContacts() {
ModelAndView modelandview = new ModelAndView("list");
modelandview.addObject("message","Your contact book");
return modelandview;
}
現在一切正常,當我瀏覽到,
http://localhost:8080/appname/list.html
但是我想要的網址是,
http://localhost:8080/appname/contact/list.html
我嘗試了該方法的使用最高@RequestMapping("/contact/list.html")
但它不幫助(顯示404錯誤與描述所請求的資源()不可用)。
這怎麼辦?
此外,是否有可能有多個網址模式的servlet映射例如。 *.html or *.do
?
PS。我在Ubuntu桌面上使用apache-tomcat
謝謝
是的,這工作。謝謝! – naiquevin 2011-02-11 04:30:47