struts-default包是在struts-default.xml文件中定义的,该文件可以在struts2-core.jar文件内的根目录下找到:
<struts>... <package name="struts-default" abstract="true"> <result-types> <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/> ... </result-types> <interceptors> <interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/> ... <interceptor-stack name="defaultStack"> <interceptor-ref name="exception"/> ... </interceptor-stack> </interceptors> <default-interceptor-ref name="defaultStack"/> <default-class-ref class="com.opensymphony.xwork2.ActionSupport" /> </package></struts>
struts-default包的内容
从struts-default.xml文件中可以看到,struts-default包含了以下一些内容:
- 抽象包。在struts-default这个package的定义中,abstract属性设置为true,因此这是一个抽象包(仅供别的包继承使用,自身不包含任何action定义)。
- 定义result type。在Struts 2.3.15.1中,总共预定义了10种result type。
- 定义拦截器(interceptor)。在Struts 2.3.15.1中,总共预定义了32种拦截器。
- 定义拦截器栈(interceptor-stack)以及默认使用的拦截器栈。在Struts 2.3.15.1中,默认使用的拦截器栈是defaultStack,内含18个顺序排列的拦截器。因此,如果自定义的package继承了struts-default而又没有任何拦截器上的修改,该自定义package使用的拦截器栈就是defaultStack。
- 定义默认action类。在Struts 2.3.15.1中,默认的action类是ActionSupport。这意味着如果某个action没有定义Class,那么ActionSupport将作为该action的class出现。观察ActionSupport源代码后即可发现:其execute()方法永远返回”SUCCESS”;因此,任何没有显式定义class的action,其用于渲染的result只有一个。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。