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里面的也得去掉

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

posted on 2012-09-02 10:38  小强斋太  阅读(433)  评论(0编辑  收藏  举报

导航