在开发过程中有时候想把index.action(或index.do)作为网站的默认首页,于是我们自然而然的想到web.xml文件,于是我们就配置了
<welcome-file-list>
<welcome-file>index.action</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
然后重启服务器发现并没什么卵用,有些人可能就放弃用xml解决,转而采用新建index.html并在index.html里面增加跳转可以解决。
例如
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.html' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="Refresh" content="0;URL=/index.action"/>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
跳转中... <br>
</body>
</html>
其中这一行执行跳转
<meta http-equiv="Refresh" content="0;URL=/index.action"/>
这样做其实也可以,但是有一个跳转的过程令人不是特别舒服,又降低了效率。
其实上面讲的都是废话,重点来了,
针对在web.xml文件里添加index.acton无法生效的问题,只需要在网站的根目录下添加一个名字叫index.action的文件,文件的内容随意。然后惊喜的发现现在配置生效了。