JavaWeb应用设置acton为默认页

本文介绍如何在Web应用中正确设置默认首页为index.action的方法,并提供了一种通过创建空的index.action文件来实现配置生效的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在开发过程中有时候想把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的文件,文件的内容随意。然后惊喜的发现现在配置生效了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值