struts2配置文件的加载顺序以及 struts.xml package 的配置说明

查看StrutsPrepareAndExecuteFilter:(核心过滤器)两个功能 :预处理 和 执行

在预处理功能中 init 方法中会有加载配置文件的代码:

dispatcher.init();

init_DefaultProperties(); // [1]                  ---- 加载org.apache.struts.default.properties.配置的是struts2的所有常量.

init_TraditionalXmlConfigurations(); // [2]       ---- 加载struts-default.xml、struts-plugin.xml、struts.xml

init_LegacyStrutsProperties(); // [3]             ---- 加载用户自定义struts.properties

init_CustomConfigurationProviders(); // [5]       ---- 加载Struts2定义Bean.

init_FilterInitParameters() ; // [6]              ---- 加载web.xml

init_AliasStandardObjects() ; // [7]              ---- 用户自定义Bean

结论:

* default.properties

* struts-default.xml

* struts-plugin.xml

* struts.xml             ---- 配置Action以及常量.(******)

* struts.properties      ---- 配置常量

* web.xml                ---- 配置核心过滤器及常量.

***** 后配置的常量 会 覆盖先配置的常量.

<package>的配置:

* package:包. 不是java中说那个包. Struts2中的包 管理<action>.

* 属性:

* name       :包名.包名是唯一的不能重复的.

* extends    :继承.继承struts-default.(struts-default包中定义结果类型和拦截器.)

* namespace  :名称空间.与<action>标签中的name属性共同决定Action的访问路径.

* 写法:

* namespace有名称:   namespace=”/aa”

* namespace只是一个/: namespance=”/”

* namespace默认的:   namespace没写.

* 有如下配置:

<package name="demo1" extends="struts-default" namespace="/aa/bb/cc">

<action name="demo1" class="cn.itcast.struts2.demo1.StrutsDemo1"/>

</package>

<package name="demo2" extends="struts-default" namespace="/aa/bb">

<action name="cc/demo1" class="cn.itcast.struts2.demo1.StrutsDemo2"/>

</package>

<package name="demo2" extends="struts-default" namespace="/aa">

<action name="bb/cc/demo1" class="cn.itcast.struts2.demo1.StrutsDemo3"/>

</package>

<package name="demo2" extends="struts-default" namespace="/">

<action name="aa/bb/cc/demo1" class="cn.itcast.struts2.demo1.StrutsDemo3"/>

</package>

在页面中<a href=”/aa/bb/cc/demo1.action”>访问</a>

***** 名称空间最大化:访问路径中:/aa/bb/cc/demo1.action 首先将/aa/bb/cc都作为名称空间.demo1作为action的name去查询.

* abstract   :抽象的.用于使其他的包可以继承的.

* <package name="struts-default" abstract="true"> . 所以可以继承struts-default.

<action>的配置:

* action:配置Action类的访问路径.

* 属性:

* name   :名称.与<package>中的namespace属性共同决定访问路径.

* class  :类的全路径.要执行的Action类的全路径.

* method :方法.用来指定Action中执行那个方法的方法名.(默认的值execute)

<result>的配置:

* result:配置Action执行后的页面跳转.

* 属性:

* name   :逻辑视图名称.(不是真实的视图,为真实的视图起了一个别名,在Action中返回这个字符串的别名,从而找到具体页面.)

* type   :跳转的类型.

Action中的默认值:

<package>的namespace的默认值: 什么都没写.

<action>的class的默认值:

* 在struts-default.xml中:

<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />

<result>的name的默认值:

* name默认就是success.

默认的Action的配置和Action的默认处理类:

默认的Action         :访问一个Action.但是这个Action路径写错了.(404的错误.配置一个默认的Action,当找不到Action的时候,让默认的Action来执行.)

* <default-action-ref name=""/>

Action默认处理类      :访问一个Action的时候,路径没有错误.但是class中类的路径写错了或者没写.

* <default-class-ref class="com.opensymphony.xwork2.ActionSupport" />

常量的配置:

修改常量:

* struts.xml         :

* 格式:<constant name="常量名称" value="常量的值"/>

* struts.properties  :

* 格式:常量的名称=常量的值.

* web.xml            :

*   <filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

<init-param>

<param-name>常量名称</param-name>

<param-value>常量值</param-value>

</init-param>

</filter>

Struts2常用的常量:

* struts.i18n.encoding=UTF-8         :解决Struts2中的所有的POST请求的中文乱码.

* struts.action.extension=action,,       :action的访问的后缀名.默认值不是.action或者空(不写后缀名也可以访问.).

* <constant name="struts.action.extension" value="action"/>

* struts.devMode=false                   :解决修改了配置文件之后不需要重启服务器.

* <constant name="struts.devMode" value="true"></constant>

分模块开发的时候

<include file="cn/itcast/struts2/demo1/struts_demo1.xml"/>  整合其他的struts的配置文件.

时间: 2024-07-30 10:15:33

struts2配置文件的加载顺序以及 struts.xml package 的配置说明的相关文章

Spring Boot配置文件的加载顺序

配置文件的加载顺序, 后加载的会覆盖先加载的:也就是properties配置文件的内容会替换掉.yml及.yaml文件的内容 原文地址:https://www.cnblogs.com/niwotaxuexiba/p/10849376.html

dubbo配置文件的加载顺序详解(图示)

Dubbo配置文件的加载顺序 ? 在使用apache dubbo.version2.7.3 时,配置文件的加载情况.以provider提供服务者为例. 配置文件 ,以下四个配置文件. 其优先级 application.properties #Dubbo config dubbo.application.name=boot-ego-user-service-provider dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.protoc

web.xml加载顺序与web.xml常用节点解析

web.xml加载顺序 应用服务器启动时web.xml加载过程,至于这些节点在xml文件中的前后顺序没有关系,不过有些应用服务器,我曾碰到过的 websphere就严格要求web.xml的节点顺序,否则部署不成功,所以还是赞成按照web.xml标准格式写 总的来说, web.xml 的加载顺序是:context-param --> listener --> filter --> servlet 其中, 如果 web.xml 中出现了相同的节点, 则是按照在配置文件中出现的先后顺序来加载的

Struts2中6大配置文件以及加载顺序

1.default.properties   默认常量配置 2.struts-default.xml   默认配置文件 3.struts-plugin.xml    插件配置文件 4.struts.xml                核心配置文件 5.struts.properties     自定义常量配置 6.web.xml                  项目配置文件 原文地址:https://www.cnblogs.com/batj/p/9116068.html

配置文件的加载顺序和位置

一共以下几种配置形式,根据顺序越往下优先级越高: 默认配置:ThinkPHP/Conf/convention.php 公共配置;Application/Common/Conf/config.php 模式配置:Application/Common/Conf/config_模式名称.php 调试配置:Application/Common/Conf/debug.php 场景配置:在Application/Common/Conf/场景名称.php     (需要在入口文件中生命,例如 : define(

MAC下bash配置文件的加载顺序

0. 启动bash时,环境变量(PATH)的值为空. 1. 将/etc/paths中的内容加入到PATH中.(这个文件不是脚本) 2. 将/etc/paths.d/目录下的每个文件中的内容加入到PATH中.(这些文件不是脚本) 3. 执行/etc/bashrc 4. 执行~/etc/.bash_profile 同学们可以自己实践一下.

hadoop配置文件加载顺序

用了一段时间的hadoop,现在回来看看源码发现别有一番味道,温故而知新,还真是这样的 在使用hadoop之前我们需要配置一些文件,hadoop-env.sh,core-site.xml,hdfs-site.xml,mapred-site.xml.那么这些文件在什么时候被hadoop使用? 一般的在启动hadoop的时候使用最多就是start-all.sh,那么这个脚本都干了些什么? start-all.sh # Start all hadoop daemons. Run this on mas

Thinkphp配置文件的加载

若应用的配置文件比较大,可以分成几个单独的配置文件或者需要加载额外的配置文件的话,可以采用扩展配置或者动态配置. 配置文件的加载顺序为: 惯例配置->应用配置->模式配置->调试配置->状态配置->模块配置->扩展配置->动态配置 在没有生效的情况下,后面的配置文件会覆盖前面的同名配置,故优先从右到左. 惯例配置:ThinkPHP/Conf/convention.php 应用配置:Application/Common/Conf/config.php 模式配置:Ap

spring-boot学习五:Spring boot配置文件的加载位置

1.配置文件的加载位置 spring boot启动的时候会加载全局配置文件application.properties(或者application.yaml)文件,这个文件默认的位置在: 即classpath:/的相对路径下.这个配置文件除了可以在resource下之外,还可以在如下位置: 在classpath:/config/即resources/config下: 在当前工程文件的config文件夹下: 在当前工程的相对路径下: 2.配置文件的加载顺序 以上所说的四个文件的优先级如下: app