关于 default-action-ref 的一个BUG 即解决方法

web.xml中:

  1. <welcome-file-list>  
  2.     <welcome-file>index.jsp</welcome-file>  
  3.   </welcome-file-list>  
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

struts.xml中:

  1. <package name="front" namespace="/" extends="struts-default">  
  2.     <default-action-ref name="index" />  
  3.       
  4.     <action name="index" class="com.demo.bbs.action.xxxAction" method="list">  
  5.         <result>/index.jsp</result>  
  6.     </action>  
  7.       
  8. </package>  
    <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。


如果需要默认进入执行xxxAction之后的 index.jsp ,则可以如下配置:

  1. <welcome-file-list>  
  2.     <welcome-file>index</welcome-file>  <!--此处是index,而不是index.jsp-->  
  3.   </welcome-file-list>  
<welcome-file-list>
    <welcome-file>index</welcome-file>  <!--此处是index,而不是index.jsp-->
  </welcome-file-list>

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




PS : 如果访问的action不存在,会跳到默认的action,比如输入 http://localhost:8080/项目名/afafdadf,则会跳到index.jsp。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值