我的目標是不映射/ {任何路徑}和*。html的映射到一個servlet/*。例如:@RequestMapping歡迎文件
map:
/foo
/foobar/
/bar.html
/foo/bar.html
don't map:
/foo.js
/bar.pdf
爲了做到這一點,我有一個servlet和歡迎文件映射像這樣:
的web.xml:
<servlet-mapping>
<servlet-name>someServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
,並在控制器,我有
@RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView showPage(HttpServletRequest request){
...
}
這將不起作用 - 該小服務程序不會在/test
上觸發。不過,我發現,如果我在/test/index.html
創建一個空白文件,然後將其確實工作 - 我假設默認的servlet以某種方式通過尋找index.html的幫助。
不幸的是,我不能依靠靜態文件。有沒有什麼辦法可以讓這個映射工作,而空白的文件,黑客和沒有映射/ *到servlet?
http://stackoverflow.com/questions/7415084/spring-welcome-file-list-correct-mapping – 2012-10-24 13:40:08