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的配置文件.
struts xml 模版
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant> <package name="package1" extends="struts-default" namespace="">
<default-action-ref name="demo2"></default-action-ref>
<default-class-ref class="cn.jiemoxiaodi.demo3.Struts2Demo3"></default-class-ref>
<action name="demo1" class="cn.jiemoxiaodi.demo1.Struts2Demo1"
method="">
<result name="success">/demo1/success.jsp</result>
</action>
<action name="demo2" class="cn.jiemoxiaodi.demo2.Struts2Demo2"
method="">
</action> <action name="demo3">
</action>
</package> <include file="cn/jiemoxiaodi/demo4/struts4.xml"></include>
<include file="cn/jiemoxiaodi/pojodemo/struts_pojo.xml"></include>
<include file="cn/jiemoxiaodi/demo5/struts_book.xml"></include>
<include file="cn/jiemoxiaodi/servletapi/struts_servletapi.xml"></include>
</struts>
struts2配置文件的加载顺序以及 struts.xml package 的配置说明的更多相关文章
- 2 Struts2的执行流程&配置文件的加载顺序
执行流程: 访问前段页面,通过url访问action 访问xml中Struts2核心过滤器,并执行一组拦截器(这组拦截器在struts-default.xml中,实现了部分功能) 通过action配置 ...
- dubbo配置文件的加载顺序详解(图示)
Dubbo配置文件的加载顺序 在使用apache dubbo.version2.7.3 时,配置文件的加载情况.以provider提供服务者为例. 配置文件 ,以下四个配置文件. 其优先级 app ...
- Spring Boot配置文件的加载顺序
配置文件的加载顺序, 后加载的会覆盖先加载的:也就是properties配置文件的内容会替换掉.yml及.yaml文件的内容
- springboot 配置文件的加载顺序
springboot 配置文件的加载顺序1.在命令行中传入的参数.2. SPRING APPLICATION JSON中的属性. SPRING_APPLICATION—JSON是以JSON格式配置在系 ...
- 「快学SpringBoot」配置文件的加载顺序和配置项默认值设置
前言 有的时候,配置信息是我们无法在开发过程中就能确定的.比如,给客户开发的项目,客户需要根据自身的情况自定义配置,如数据库配置,加密密钥配置等等.这时候,就需要把配置文件放在外面,让用户自定义配置部 ...
- linux下/etc/profile /etc/bashrc /root/.bashrc /root/.bash_profile这四个配置文件的加载顺序
目录 一.关于linux配置文件 二.验证四个配置文件的加载顺序 三.结论 一.关于linux配置文件 1.linux下主要有四个配置文件:/etc/profile ./etc/bashrc ./ro ...
- web项目中配置文件的加载顺序
当一个项目启动时,首先是web.xml: 这里面的配置: 为什么要在web.xml中配置struts的过滤器? 因为一个web项目运行的时需要加载的,或者默认的部分配置都会在web.xml中配置,中间 ...
- SpringBoot配置文件优先级加载顺序
- struts2配置文件加载顺序
struts2配置文件加载顺序: struts-default.xml/ struts-plugin.xml/ struts.xml/ struts.properties/ web.xml
随机推荐
- linux下设置进程优先级方法!
Linux系统下提升进程优先级的办法 Linux系统进程的优先级取值:-20 到 19,数越大优先级越低. 可以通过top命令来查看,NI那一列. 改变进程的优先级的方法有两种: www ...
- Html书写规范
#cnblogs_post_body ol { padding-left: 0px; } body { line-height: 1.6; } body, th, td, button, input, ...
- Python3中urllib详细使用方法(header,代理,超时,认证,异常处理)
urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)了,我们可以利用它来抓取远程的数据进行保存哦,下面整理了一些关于urllib使用中的一些 ...
- 装X之读书籍
.读书又记不住...读过又有什么用...读万卷书 == 读0卷书 ? .额.读书不是记住的,毕竟哪里有这么多过目不忘的天才...要理解书中的内容...理解... .还是要记的,但是要理解的基础上记住. ...
- 编译本地64位版本的hadoop-2.6.0
官方提供的hadoop-2.x版本貌似都是32位的,在64位机子下使用可能会报错,最好使用官方提供的源码进行本地编译,编译成适合本地硬件环境的64位软件包. 关于native Hadoop是使用J ...
- zookeeper集群配置与启动——实战
1,准备: A:三台linxu服务器: 10.112.29.177 10.112.29.172 10.112.29.174 命令 hostname 得到每台机器的 hostname vm-10-112 ...
- select2
.select2-container .select2-choice { height: 34px; line-height: 34px; } .自定义 组件高度 在css 里面设置 .select2 ...
- 打开Excel的报错,提示:不能使用对象链接和嵌入
计算机这几天在打开Excel文档的时候,提示:不能使用对象链接和嵌入, 而且出现如下的提示:Microsoft Office Excel进程已停止工作, 每次打开Excel的时候都是同样的问题,害我跟 ...
- 在使用开源library的PullToRefreshView中
下拉刷新几乎是每个应用都会有的功能,且大部分用的都是开源项目,下载地址:下拉刷新.如何在页面刚打开的时候自动触发下拉刷新的呢? 只需要一句代码,在PullToRefreshAdapterView Ba ...
- json不转化值是null的字段
今天写东西,发现JSONObject.fromObject(),方法,会把value是null的字段,转为0或"",就自己写了一个方法,如果value是null就不转换 packa ...