1-1 struts2 基本配置 struts.xml配置文件详解
详见http://www.cnblogs.com/dooor/p/5323716.html
一. struts2工作原理(网友总结,千遍一律)
1 客户端初始化一个指向Servlet容器(例如Tomcat)的请求
2 这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做ActionContextCleanUp的可选过滤器,这个过滤器对于Struts2和其他框架的集成很有帮助,例如:SiteMesh Plugin)
3 接着FilterDispatcher被调用,FilterDispatcher询问ActionMapper来决定这个请是否需要调用某个Action
4 如果ActionMapper决定需要调用某个Action,FilterDispatcher把请求的处理交给ActionProxy
5 ActionProxy通过Configuration Manager询问框架的配置文件,找到需要调用的Action类
6 ActionProxy创建一个ActionInvocation的实例。
7 ActionInvocation实例使用命名模式来调用,在调用Action的过程前后,涉及到相关拦截器(Intercepter)的调用。
8 一旦Action执行完毕,ActionInvocation负责根据struts.xml中的配置找到对应的返回结果。返回结果通常是(但不总是,也可 能是另外的一个Action链)一个需要被表示的JSP或者FreeMarker的模版。在表示的过程中可以使用Struts2 框架中继承的标签。在这个过程中需要涉及到ActionMapper
在上述过程中所有的对象(Action,Results,Interceptors,等)都是通过ObjectFactory来创建的。
二.struts2基本配置
<struts>
<!-- 开发模式下使用,打印更多详细错误信息 -->
<constant name="struts.devMode" value="true" />
<!-- 国际化 -->
<constant name="struts.i18n.encoding" value="UTF-8"/>
<!-- 允许ognl访问静态方法 -->
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<!--
该属性指定需要struts2处理的请求后缀,默认值是action,即,所有匹配*.action的请求
都由struts2处理,如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号","隔开
-->
<constant name="struts.action.extension" value="action"/>
<!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false"/>
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值false:不重新加载 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 默认的视图主题 -->
<constant name="struts.ui.theme" value="simple"/>
<!-- 与spring集成时,指定由spring负责管理action对象的创建 -->
<constant name="struts.objectFactory" value="spring"/>
<!-- 该属性设置struts2是否支持动态方法调用,默认值true:支持 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<!-- 上传文件的大小限制 -->
<constant name="struts.multipart.maxSize" value="10701096"/>
<!-- 引入文件 -->
<include file="cn/qjc/action/login/login.xml"></include>
<include file="cn/qjc/action/demo/demo01.xml"></include>
<include file="cn/qjc/interceptor/interceptor.xml"></include>
</struts>
struts2配置文件加载顺序
a、default.properties:struts2-core**.jar org.apache.struts包中(程序员只能看)
b、struts-default.xml:struts2-core**.jar中(程序员只能看)
c、struts-plugin.xml:在插件的jar包中(程序员只能看)
d、struts.xml:在应用的构建路径顶端。自己定义的Struts配置文件(推荐)
e、struts.properties:在应用的构建路径顶端。程序员可以编写(不推荐)
f、web.xml:配置过滤器时,指定参数。程序员可以编写(不推荐)
特别注意:顺序是固定的。后面的配置会覆盖前面的同名配置信息。
加载struts.xml过程
说明:
1、 在启动的时候加载了三个配置文件 struts-default.xml、struts-plugin.xml、struts.xml
2、 如果这三个文件有相同的项,后面覆盖前面的。
3、 struts.xml文件必须放在src下才能找到。
2.2 package元素
意义:分模块开发
属性:
name:必须的。配置文件中要唯一。就是一个名字。
extends:指定父包。会把父包中的配置内容继承下来。一般需要直接或间接的继承一个叫做“struts-default”的包(在struts-default.xml配置文件中)。
如果不继承该包,那么Struts2中的核心功能将无法使用。
abstract:是否是抽象包。没有任何action子元素的package可以声明为抽象包。
namespace:指定名称空间。一般以”/”开头。该包中的动作访问路径:namesapce+动作名称。如果namespace=””,这是默认名称空间,和不写该属性是一样的。
2.3 action配置
作用:定义一个动作。
属性:
name:必须的。动作名称。用户用于发起请求。在包中要唯一。
class:指定动作类的全名。框架会通过反射机制实例化。默认是:com.opensymphony.xwork2.ActionSupport。
method:指定动作类中的动作方法。框架会执行该方法。默认是execute()。
<!-- 配置全局视图:访问动作时没有局部视图,则找全局视图 -->
<package name="default" extends="struts-default" abstract="true">
<global-results>
<result name="success">/WEB-INF/login/success.jsp</result>
</global-results>
</package>
<package name="login" namespace="/user" extends="default">
<action name="login" class="cn.qjc.action.login.Login" method="login">
<!-- type默认dispatcher 表示请求转发 -->
<result name="success" type="dispatcher">/WEB-INF/login/success.jsp</result>
<result name="error">/WEB-INF/login/error.jsp</result>
</action>
</package>
1-1 struts2 基本配置 struts.xml配置文件详解的更多相关文章
- struts2学习笔记--struts.xml配置文件详解
这一节主要讲解struts2里面的struts.xml的常用标签及作用: 解决乱码问题 <constant name="struts.i18n.encoding" value ...
- struts2.0中struts.xml配置文件详解
先来展示一个配置文件 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration ...
- 转载 Struts2的配置 struts.xml Action详解
在学习struts的时候,我们一定要掌握struts2的工作原理.只有当我们明确了在struts2框架的内部架构的实现过程,在配置整个struts 的框架时,可以很好的进行逻辑上的配置.接下来我就先简 ...
- struts2:struts.xml配置文件详解
1. 几个重要的元素 1.1 package元素 package元素用来配置包.在Struts2框架中,包是一个独立的单位,通过name属性来唯一标识包.还可以通过extends属性让一个包继承另一个 ...
- struts2中struts.xml配置文件详解【未整理】
1. 深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1. 包配置: Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管 ...
- struts2中struts.xml配置文件详解
struts.xml的常用配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts ...
- struts2 struts.xml配置文件详解
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quo ...
- struts2.0 struts.xml配置文件详解
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quo ...
- sqlMapConfig.xml配置文件详解
sqlMapConfig.xml配置文件详解: Xml代码 Xml代码 <? xml version="1.0" encoding="UTF-8" ?& ...
随机推荐
- mysql 集群 监控
部署mysql高可用集群(mysql-mmm+主从同步)4台数据库服务器:四个数据库之保留初始的四个库,其他库全部删除 主机158 主机137 主机99 主机67 主机102(可与其他四台ping通即 ...
- 5_Longest Palindromic Substring(Manacher) --LeetCode
参考:https://www.felix021.com/blog/read.php?2040,https://segmentfault.com/a/1190000002991199 做了修改. 首先用 ...
- PlateSpin备份服务器时SQL Server的一些活动信息
以前写过一篇文章IO is frozen on database xxx, No user action is required", 主要是介绍PlateSpin在服务器层面做DR备份时 ...
- SyntaxError: Missing parentheses in call to 'print'
C:\Users\konglb>python Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (I ...
- Android的微信智能心跳方案
原文地址: 年11月中旬时,因为基础组件组人手紧张,Leo安排我和春哥去广州轮岗支援.刚到广州的时候,Ray让我和春哥对Line和WhatsApp的心跳机制进行分析.我和春哥抓包测试了差不多两个多礼拜 ...
- Linux下搭建SVN服务器遇到的问题及解决方法,
1.checkout时,提示:URL svn://192.168.1.99/svntest doesn't exist... 奇怪,怎么会提示库不存在呢?肯定是哪里配置问题.后来尝试了半天,也在网上搜 ...
- phpcmsv9更换模板介绍
先分享下大概的步骤: 1.上传模版文件到服务器:2.在站点管理 里边[模板风格配置]选择新模板:3.设置不同模型对应模板:4.修改现有的栏目,匹配新模板:5.更新栏目缓存.系统缓存,更新HTML静态页 ...
- PHP常见错误
1.关于单引号和双引号的区别. $sql="insert into tableName values ('".$name."','".$email." ...
- OpenGL结合C#进行绘图
转自:http://www.cnblogs.com/wangshide/archive/2012/04/14/2447499.html 本人对OpenGL产生了浓厚的兴趣,又想学习一下C#这个语言,就 ...
- 如何让window.open()以post请求方式调用(巧妙解法)
问题由来: 在公司遇到一个线上bug,如下 var url = 'http://106.75.31.215:8012/onlinePreview?url=' + encodeURIComponent( ...