Spring欢迎文件列表正确映射
问题内容:
我知道在spring我必须定义welcome-file,该文件应该在WEB-INF文件夹之外,因此我将其定义为:
web.xml:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
但是实际上我真正的代码在WEB-INF / jsp / contact.jsp中
所以我总是必须这样做:
<jsp:forward page="/index"></jsp:forward>
在我的控制器中,这意味着:
@RequestMapping("/index")
public String listContacts(Map<String, Object> map) {
map.put("contact", new Contact());
map.put("contactList", contactService.listContact());
return "contact";
}
我该怎么做,欢迎文件总是进入我的索引映射,从而导致contact.jsp?
如果这令人困惑,请随时提问。
问题答案:
@RequestMapping({"/index", "/"})
和
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
为我工作。