struts2的default-action-ref 的一个“BUG”(其实并非bug)

来源:互联网 发布:新浪期货软件下载 编辑:程序博客网 时间:2024/06/05 11:57

struts.xml中:

<package name="front" namespace="/" extends="struts-default"> 
    <default-action-ref name="index" /> 
     
    <action name="index" class="com.demo.bbs.action.xxxAction" method="list"> 
        <result>/index.jsp</result> 
    </action> 
     
</package> 

输入:http://localhost:8080/项目名/ , 会进入 web.xml 中的 index.jsp ,假设此是 web.xml 中是 a.jsp,则会进入 a.jsp 的界面。

此时如果输入:http://localhost:8080/项目名/index,则会进入执行了xxxAction 之后的 index.jsp。


如果 web.xml 中的 <welcome-file-list> 被注释掉,即 web.xml 中没有默认的页面,则会在 struts.xml 中找 default-action-ref 。

此时如果输入:http://localhost:8080/项目名/,则会进入 index.jsp ,但是没有执行 xxxAction ,只是简单的输出 index.jsp。

 

原因是:

其实“如果 web.xml 中的 <welcome-file-list> 被注释掉,即 web.xml 中没有默认的页面...”这句话是错误的,虽然项目下的web.xml是被注释掉,但并不代表tomcat在其它的地方没有默认的<welcome-file-list>,实际上在tomcat的conf目录下的web.xml里的最后几行有<welcome-file-list>的默认值,而项目下的web.xml之所以有<welcome-file-list>,这只不过是向开发人员提供了一个修改<welcome-file-list>的方式。如果你把tomcat/conf下的web.xml里的“<welcome-file>index.jsp</welcome-file>”注释掉的话就不会出现不执行action的现象了(需重启tomcat)。所以说这不是一个bug,只是tomcat配置问题,大家可以再试试哈~!


 


原创粉丝点击