Struts2---->default-action-ref

       default-action-ref定义的action和web.xml中的welcome-file定义的视图的优先访问顺序

注意:tomcat-6.0.18\conf下面web.xml中的welcome-file定义的视图配置对于项目也起作用

<welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

一、当在struts.xml中配置default-action-ref时,(namespace="/">)命名空间是单独的斜杠

<package name="user" extends="struts-default" namespace="/">
       <default-action-ref name="userAdd"></default-action-ref>
       
        <action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add">
            <result>/user_add_success.jsp</result>
        </action>
        
    </package>


1、在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref时,访问的是index.jsp,说明welcome-file起作用

2、在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref/时,访问的是index.jsp,说明welcome-file起作用

3、在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref/abcde时,访问的是user_add_success.jsp,

     default-action-ref配置才起作用。

去掉web.xml中的welcome-file定义的视图配置(tomcat-6.0.18\conf下面web.xml里面的也得去掉

以上三种情况都起作用

 二、如果把Struts.xml配置成如下(namespace="/user"):命名空间不是单独的斜杠

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />
    <package name="user" extends="struts-default" namespace="/user">
       <default-action-ref name="userAdd"></default-action-ref>
       
        <action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add">
            <result>/user_add_success.jsp</result>
        </action>
        
    </package>
</struts>

1、当在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref时,访问的是index.jsp

2、当在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref/时,访问的是index.jsp

3、当在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref/abcde时,

Messages:
  • There is no Action mapped for namespace / and action name abcde.

4、当在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref/user,

Messages:
  • There is no Action mapped for namespace / and action name user.

5、当在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref/user/,访问的才是user_add_success.jsp,default-action-ref配置起作用。

6、当在浏览器中敲http://localhost:8080/Struts2_default_Action_Ref/user/dfsa,访问的才是user_add_success.jsp,default-action-ref配置起作用。

去掉web.xml中的welcome-file定义的视图配置(tomcat-6.0.18\conf下面web.xml里面的也得去掉

前四种全是错误,后两种起作用。

转载于:https://my.oschina.net/wangshengzhuang/blog/785189

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值