Spring welcome-file-list正确映射 [英] Spring welcome-file-list correct mapping
本文介绍了Spring welcome-file-list正确映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在春天我必须定义welcome-file,它应该在WEB-INF文件夹之外,所以我这样定义:
I know that in spring I must define welcome-file, which should be outside of WEB-INF folder, so I define it like this:
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
But actually my real code is in WEB-INF/jsp/contact.jsp
所以我总是这样做:
<jsp:forward page="/index"></jsp:forward>
在我的控制器中,这意味着:
And in my controller this means:
@RequestMapping("/index")
public String listContacts(Map<String, Object> map) {
map.put("contact", new Contact());
map.put("contactList", contactService.listContact());
return "contact";
}
我怎么能这样做,欢迎文件总是送到我的索引映射,导致contact.jsp?
How can I make it this way, that welcome-file always goes to my index mapping, which leads to contact.jsp?
如果这令人困惑,请随意提问...
Feel free to ask questions, if this was confusing...
推荐答案
@RequestMapping({"/index", "/"})
和
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
为我工作。
这篇关于Spring welcome-file-list正确映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文