将默认首页设置成index.do的方法

来源:互联网 发布:电路板设计软件 编辑:程序博客网 时间:2024/05/14 23:31

      最近做了一个手机论坛,表现层用的struts,首页在struts里配置为index.do。但是由于web.xml里面的默认页配置welcome-file 必须为物理存在的文件,那么对于index.do这样的首页,tomcat就不会继续往下处理,而直接返回404了。

      但是我又非常迫切、非常盼望、非常渴望使用index.do做首页,怎么办?

      Tomcat中用一段注释:

      When a request URI refers to a directory, the default servlet looks for a "welcome file" within that directory and, if present,  to the corresponding resource URI for display 。

      意思就是说,tomcat只要找到存在这样一个名字的物理文件,就会转到下面继续处理,那么简单了,在目录下建一个空的文件,名字就是index.do(小小的欺骗了一下tomcat),一切就搞定了!