welcome
今天要把首页换成velociy的,发现直接修改welcome-file为一个action请求不生效。
经过查询资料发现有如下三种解决办法:
1. <welcome-file-list>
<welcome-file>/index.action</welcome-file>
</welcome-file-list>
然后在webapp目录下新建一个空文件index.action
2. <welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
在jsp中做重定向跳转
3.<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
在html中使用META重定向操作:<META HTTP-EQUIV="Refresh" CONTENT="0;URL=max/HelloWorld.action">
其中,content="1 是时间控制,表示1秒后自动跳转到要跳转的页面. content="0 表示打开该页后立即跳转到你要跳转的页面. url 是要跳转的路径
综上所述,个人感觉第一个方法简洁方便快速。当欢迎页面查找index.action,并进行页面请求时会经过struts拦截器,从而间接的发起action请求。
分析问题原因:
1. 这是由于web.xml中的welcome-file-list配置段仅对servlet和普通页面有效,其他不支持
2. 因为struts2采用过滤器的方式处理请求,默认情况是监控url地址的变化
参考资料地址:.html
.jd?id=y0hi94eg4l