struts2_struts.xml配置文件讲解

     

1.bean

  Bean详细讲解:https://www.cnblogs.com/lulu638/p/4340703.html

2.constant

  constant属性配置,可配置的属性可以参考default.properties(在struts2-core-2.3.24.jar包/org/apache/struts2/default.properties)

 1 <struts>
 2     <!-- 乱码解决 -->
 3     <constant name="struts.i18n.encoding" value="UTF-8"></constant>
 4     <!-- 自定义拓展名 -->
 5     <constant name="struts.action.extension" value="action,,ahd"></constant>
 6     <!--设置开发模式,使显示的界面更加友好-->
 7     <constant name="struts.devMode" value="true"></constant>>
 8     <!--设置配置文件修改后自动加载,仅推荐在开发中使用-->
 9     <constant name="struts.configuration.xml.reload" value="true"></constant>
10 </struts>

3.include

  struts.xml文件使用include标签可以包含其他xml文件内容,适合团队协作,每人做自己的部分,最后在struts.xml文件中使用include标签包含其他人的配置文件

<include file="com/ahd/strutsXml/hello.xml"></include>

4.package

  Struts2使用包来组织Action,将Action放在包下来定义,通过package元素配置一个包,通过package的子元素action来定义一个Action;

  Struts2框架中核心组件就是Action、拦截器等,Struts2使用包来管理Action和拦截器等。每个包就是多个Action、拦截器引用的集合。

    <package name="login" extends="struts-default" namespace="/">
        <action name="login" class="com.ahd.action.LoginAction">
            <result name="success">/hello.jsp</result>
        </action>
    </package>  

  name属性:包package必须指定name值,作为引用该包的唯一标识

  extends:可选属性,指定子包可以继承一个或多个父包的Action和拦截器等配置, 指定package继承另一package的所有配置。通常情况下,我们使用struts-default作为package的基础。,一般默认继承struts的默认文件:struts-defaule.xml配置文件,继承多个父包时用”,”隔开.  

  namespace:可选属性, Actions的唯一命名空间,定义带包的命名空间,默认是””,处理时 命名空间/actionName

  abstract:可选属性,指定该包是否是一个抽象包, 定义package为抽象的。如果标记为true,则package不能被最终用户使用。

  action元素:

    name属性:必须属性,用来配置action的url

    class属性:非必须属性,可有可无,有则配置上action实现类的完整类名,没有则struts框架会根据name属性自动匹配action实现类

    method属性:用来指定调用action实现类的哪个方法,如果没有配置该属性,该属性默认为action实现类的execute方法.

    convert属性:非必须属性,应用于action的类型转换的完整类名

      

原文地址:https://www.cnblogs.com/aihuadung/p/9856911.html