第1:
在struts1.x中, struts框架是通过Servlet启动的。在struts2中,struts框架是通过Filter启动的。他在web.xml中的配置如下:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<!-- 自从Struts 2.1.3以后,下面的FilterDispatcher已经标注为过时
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> -->
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在StrutsPrepareAndExecuteFilter的init()方法中将会读取类路径下默认的配置文件struts.xml完成初始化操作。
注意:struts2读取到struts.xml的内容后,以javabean形式存放在内存中,以后struts2对用户的每次请求处理将使用内存中的数据,而不是每次都读取struts.xml文件 (struts1也是这样的)
注:
在文档中:
org.apache.struts2.dispatcher
Class FilterDispatcher
Class FilterDispatcher
Deprecated. Since Struts 2.1.3, use
StrutsPrepareAndExecuteFilter
instead or StrutsPrepareFilter
and StrutsExecuteFilter
if needing using the ActionContextCleanUp
filter in addition to this one
第2:
在struts2的配置文件中父包必须在子包之前定义。
包的<package>标签的namespace属性和文件系统路径有区别的,namespace只有一个级别。
第3:
struts2是按照下面这个顺序搜索常量,越靠后的文件优先级越高。
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml
第4:
每一个包中都可以有他自己的默认action,但是每一个名称空间应该有一个默认的action、如果具有相同名称空间的多个包中都声明了默认action,那么哪一个action才是默认的无法保证。注:默认的action只对action的访问有效。