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配置问题,大家可以再试试哈~!
本文详细解释了在Struts框架中如何配置默认动作,并探讨了web.xml与struts.xml文件中配置项之间的交互作用。当web.xml中的欢迎页配置被注释掉时,Struts将查找struts.xml中的默认动作引用。
523

被折叠的 条评论
为什么被折叠?



