struts-default.xml文件详解

299 篇文章 5 订阅

struts-default.xml是Struts 2 框架的基础配置文件,为框架提供默认设置,这个文件包含在Struts2-core-2.0.11.jar中,由框架自动加载。

struts-default.xml文件会自动被包含在struts.xml文件中,以提供标准的配置设置而不需要复制其内容。我们在配置strut.xml文件时,给出了下面这句代码

<package name="default" extends="struts-default">

struts-default.xml包就是在struts-default.xml文件中定义的,在这个包中定义了Struts2 内置的结果类型(包括Servlet转发、Servlet重定向、FreeMarker模板输出、XSTL渲染和ActionChainResult等),内置的拦截器,以及由不同拦截器组成的拦截器栈,这些拦截器栈可以直接使用,也可以作为自定义的拦截器栈的基础。在Struts-default.xml文件中最后还定义了默认的拦截器引用。

struts-default代码的详细解释如下:

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!--  
  3. /*  
  4.  * $Id: struts-default.xml 559615 2007-07-25 21:25:25Z apetrelli $  
  5.  *  
  6.  * Licensed to the Apache Software Foundation (ASF) under one  
  7.  * or more contributor license agreements.  See the NOTICE file  
  8.  * distributed with this work for additional information  
  9.  * regarding copyright ownership.  The ASF licenses this file  
  10.  * to you under the Apache License, Version 2.0 (the  
  11.  * "License"); you may not use this file except in compliance  
  12.  * with the License.  You may obtain a copy of the License at  
  13.  *  
  14.  *  http://www.apache.org/licenses/LICENSE-2.0  
  15.  *  
  16.  * Unless required by applicable law or agreed to in writing,  
  17.  * software distributed under the License is distributed on an  
  18.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY  
  19.  * KIND, either express or implied.  See the License for the  
  20.  * specific language governing permissions and limitations  
  21.  * under the License.  
  22.  */  
  23. -->  
  24.   
  25. <!DOCTYPE struts PUBLIC  
  26.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  27.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  28.   
  29. <struts>  
  30.     <!--struts2中工厂bean的定义-->  
  31.     <bean class="com.opensymphony.xwork2.ObjectFactory" name="xwork" />  
  32.     <bean type="com.opensymphony.xwork2.ObjectFactory" name="struts" class="org.apache.struts2.impl.StrutsObjectFactory" />  
  33.   
  34.     <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="xwork" class="com.opensymphony.xwork2.DefaultActionProxyFactory"/>  
  35.     <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="struts" class="org.apache.struts2.impl.StrutsActionProxyFactory"/>  
  36.   
  37.     <!--类型检测bean的定义-->  
  38.     <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="tiger" class="com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer"/>  
  39.     <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="notiger" class="com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer"/>  
  40.     <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="struts" class="com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer"/>  
  41.   
  42.     <!--文件上传bean的定义-->  
  43.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts" class="org.apache.struts2.dispatcher.mapper.DefaultActionMapper" />  
  44.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="composite" class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />  
  45.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful" class="org.apache.struts2.dispatcher.mapper.RestfulActionMapper" />  
  46.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful2" class="org.apache.struts2.dispatcher.mapper.Restful2ActionMapper" />  
  47.   
  48.     <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="struts" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default" optional="true"/>  
  49.     <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default" optional="true" />  
  50.   
  51.     <!--标签库bean的定义-->  
  52.     <bean type="org.apache.struts2.views.TagLibrary" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />  
  53.   
  54.     <!--一些常用视图bean的定义-->  
  55.     <bean class="org.apache.struts2.views.freemarker.FreemarkerManager" name="struts" optional="true"/>  
  56.     <bean class="org.apache.struts2.views.velocity.VelocityManager" name="struts" optional="true" />  
  57.   
  58.     <bean class="org.apache.struts2.components.template.TemplateEngineManager" />  
  59.     <bean type="org.apache.struts2.components.template.TemplateEngine" name="ftl" class="org.apache.struts2.components.template.FreemarkerTemplateEngine" />  
  60.     <bean type="org.apache.struts2.components.template.TemplateEngine" name="vm" class="org.apache.struts2.components.template.VelocityTemplateEngine" />  
  61.     <bean type="org.apache.struts2.components.template.TemplateEngine" name="jsp" class="org.apache.struts2.components.template.JspTemplateEngine" />  
  62.   
  63.     <!--类型转换bean的定义-->  
  64.     <bean type="com.opensymphony.xwork2.util.XWorkConverter" name="xwork1" class="com.opensymphony.xwork2.util.XWorkConverter" />  
  65.     <bean type="com.opensymphony.xwork2.util.XWorkConverter" name="struts" class="com.opensymphony.xwork2.util.AnnotationXWorkConverter" />  
  66.     <bean type="com.opensymphony.xwork2.TextProvider" name="xwork1" class="com.opensymphony.xwork2.TextProviderSupport" />  
  67.     <bean type="com.opensymphony.xwork2.TextProvider" name="struts" class="com.opensymphony.xwork2.TextProviderSupport" />  
  68.   
  69.     <!--Struts2中一些可以静态注入的bean,也就是不需要实例化的-->  
  70.     <bean class="com.opensymphony.xwork2.ObjectFactory" static="true" />  
  71.     <bean class="com.opensymphony.xwork2.util.XWorkConverter" static="true" />  
  72.     <bean class="com.opensymphony.xwork2.util.OgnlValueStack" static="true" />  
  73.     <bean class="org.apache.struts2.dispatcher.Dispatcher" static="true" />  
  74.     <bean class="org.apache.struts2.components.Include" static="true" />  
  75.     <bean class="org.apache.struts2.dispatcher.FilterDispatcher" static="true" />  
  76.     <bean class="org.apache.struts2.views.util.ContextUtil" static="true" />  
  77.     <bean class="org.apache.struts2.views.util.UrlHelper" static="true" />  
  78.     <!--定义Struts2默认包-->  
  79.     <package name="struts-default" abstract="true">  
  80.         <!--结果类型的种类-->  
  81.         <result-types>  
  82.             <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>  
  83.             <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>  
  84.             <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>  
  85.             <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>  
  86.             <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>  
  87.             <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>  
  88.             <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>  
  89.             <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>  
  90.             <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>  
  91.             <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />  
  92.             <!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 -->  
  93.             <result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>  
  94.             <result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" />  
  95.         </result-types>  
  96.   
  97.  `<!--Struts2中拦截器的定义-->  
  98.         <interceptors>  
  99.             <interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/>  
  100.             <interceptor name="autowiring" class="com.opensymphony.xwork2.<a href="http://lib.csdn.net/base/javaee" class='replace_word' title="Java EE知识库" target='_blank' style='color:#df3434; font-weight:bold;'>spring</a>.interceptor.ActionAutowiringInterceptor"/>  
  101.             <interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/>  
  102.             <interceptor name="conversionError" class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"/>  
  103.             <interceptor name="cookie" class="org.apache.struts2.interceptor.CookieInterceptor"/>  
  104.             <interceptor name="createSession" class="org.apache.struts2.interceptor.CreateSessionInterceptor" />  
  105.             <interceptor name="debugging" class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" />  
  106.             <interceptor name="externalRef" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor"/>  
  107.             <interceptor name="execAndWait" class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor"/>  
  108.             <interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/>  
  109.             <interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor"/>  
  110.             <interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor"/>  
  111.             <interceptor name="logger" class="com.opensymphony.xwork2.interceptor.LoggingInterceptor"/>  
  112.             <interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>  
  113.             <interceptor name="scopedModelDriven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>  
  114.             <interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/>  
  115.             <interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor"/>  
  116.             <interceptor name="staticParams" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>  
  117.             <interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor"/>  
  118.             <interceptor name="servletConfig" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>  
  119.             <interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/>  
  120.             <interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"/>  
  121.             <interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/>  
  122.             <interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>  
  123.             <interceptor name="validation" class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/>  
  124.             <interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/>  
  125.             <interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" />  
  126.             <interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" />  
  127.             <interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" />  
  128.             <interceptor name="roles" class="org.apache.struts2.interceptor.RolesInterceptor" />  
  129.   
  130.             <!--一个基本的拦截器栈-->  
  131.             <interceptor-stack name="basicStack">  
  132.                 <interceptor-ref name="exception"/>  
  133.                 <interceptor-ref name="servletConfig"/>  
  134.                 <interceptor-ref name="prepare"/>  
  135.                 <interceptor-ref name="checkbox"/>  
  136.                 <interceptor-ref name="params"/>  
  137.                 <interceptor-ref name="conversionError"/>  
  138.             </interceptor-stack>  
  139.   
  140.             <!-- 简单的validation and workflow栈 -->  
  141.             <interceptor-stack name="validationWorkflowStack">  
  142.                 <interceptor-ref name="basicStack"/>  
  143.                 <interceptor-ref name="validation"/>  
  144.                 <interceptor-ref name="workflow"/>  
  145.             </interceptor-stack>  
  146.   
  147.             <!--文件上传的拦截器栈-->  
  148.             <interceptor-stack name="fileUploadStack">  
  149.                 <interceptor-ref name="fileUpload"/>  
  150.                 <interceptor-ref name="basicStack"/>  
  151.             </interceptor-stack>  
  152.   
  153.             <!-- Sample model-driven stack  -->  
  154.             <interceptor-stack name="modelDrivenStack">  
  155.                 <interceptor-ref name="modelDriven"/>  
  156.                 <interceptor-ref name="basicStack"/>  
  157.             </interceptor-stack>  
  158.   
  159.             <!--Action链的拦截器栈-->  
  160.             <interceptor-stack name="chainStack">  
  161.                 <interceptor-ref name="chain"/>  
  162.                 <interceptor-ref name="basicStack"/>  
  163.             </interceptor-stack>  
  164.   
  165.             <!--i18n拦截器栈-->  
  166.             <interceptor-stack name="i18nStack">  
  167.                 <interceptor-ref name="i18n"/>  
  168.                 <interceptor-ref name="basicStack"/>  
  169.             </interceptor-stack>  
  170.   
  171.             <!-- An example of the params-prepare-params trick. This stack  
  172.                  is exactly the same as the defaultStack, except that it  
  173.                  includes one extra interceptor before the prepare interceptor:  
  174.                  the params interceptor.  
  175.   
  176.                  This is useful for when you wish to apply parameters directly  
  177.                  to an object that you wish to load externally (such as a DAO  
  178.                  or database or service layer), but can't load that object  
  179.                  until at least the ID parameter has been loaded. By loading  
  180.                  the parameters twice, you can retrieve the object in the  
  181.                  prepare() method, allowing the second params interceptor to  
  182.                  apply the values on the object. -->  
  183.             <interceptor-stack name="paramsPrepareParamsStack">  
  184.                 <interceptor-ref name="exception"/>  
  185.                 <interceptor-ref name="alias"/>  
  186.                 <interceptor-ref name="params"/>  
  187.                 <interceptor-ref name="servletConfig"/>  
  188.                 <interceptor-ref name="prepare"/>  
  189.                 <interceptor-ref name="i18n"/>  
  190.                 <interceptor-ref name="chain"/>  
  191.                 <interceptor-ref name="modelDriven"/>  
  192.                 <interceptor-ref name="fileUpload"/>  
  193.                 <interceptor-ref name="checkbox"/>  
  194.                 <interceptor-ref name="staticParams"/>  
  195.                 <interceptor-ref name="params"/>  
  196.                 <interceptor-ref name="conversionError"/>  
  197.                 <interceptor-ref name="validation">  
  198.                     <param name="excludeMethods">input,back,cancel</param>  
  199.                 </interceptor-ref>  
  200.                 <interceptor-ref name="workflow">  
  201.                     <param name="excludeMethods">input,back,cancel</param>  
  202.                 </interceptor-ref>  
  203.             </interceptor-stack>  
  204.   
  205.             <!-- A complete stack with all the common interceptors in place.  
  206.                  Generally, this stack should be the one you use, though it  
  207.                  may do more than you need. Also, the ordering can be  
  208.                  switched around (ex: if you wish to have your servlet-related  
  209.                  objects applied before prepare() is called, you'd need to move  
  210.                  servlet-config interceptor up.  
  211.   
  212.                  This stack also excludes from the normal validation and workflow  
  213.                  the method names input, back, and cancel. These typically are  
  214.                  associated with requests that should not be validated.  
  215.                  -->  
  216.             <interceptor-stack name="defaultStack">  
  217.                 <interceptor-ref name="exception"/>  
  218.                 <interceptor-ref name="alias"/>  
  219.                 <interceptor-ref name="servletConfig"/>  
  220.                 <interceptor-ref name="prepare"/>  
  221.                 <interceptor-ref name="i18n"/>  
  222.                 <interceptor-ref name="chain"/>  
  223.                 <interceptor-ref name="debugging"/>  
  224.                 <interceptor-ref name="profiling"/>  
  225.                 <interceptor-ref name="scopedModelDriven"/>  
  226.                 <interceptor-ref name="modelDriven"/>  
  227.                 <interceptor-ref name="fileUpload"/>  
  228.                 <interceptor-ref name="checkbox"/>  
  229.                 <interceptor-ref name="staticParams"/>  
  230.                 <interceptor-ref name="params">  
  231.                   <param name="excludeParams">dojo/..*</param>  
  232.                 </interceptor-ref>  
  233.                 <interceptor-ref name="conversionError"/>  
  234.                 <interceptor-ref name="validation">  
  235.                     <param name="excludeMethods">input,back,cancel,browse</param>  
  236.                 </interceptor-ref>  
  237.                 <interceptor-ref name="workflow">  
  238.                     <param name="excludeMethods">input,back,cancel,browse</param>  
  239.                 </interceptor-ref>  
  240.             </interceptor-stack>  
  241.   
  242.             <!-- The completeStack is here for backwards compatibility for  
  243.                  applications that still refer to the defaultStack by the  
  244.                  old name -->  
  245.             <interceptor-stack name="completeStack">  
  246.                 <interceptor-ref name="defaultStack"/>  
  247.             </interceptor-stack>  
  248.   
  249.             <!-- Sample execute and wait stack.  
  250.                  Note: execAndWait should always be the *last* interceptor. -->  
  251.             <interceptor-stack name="executeAndWaitStack">  
  252.                 <interceptor-ref name="execAndWait">  
  253.                     <param name="excludeMethods">input,back,cancel</param>  
  254.                 </interceptor-ref>  
  255.                 <interceptor-ref name="defaultStack"/>  
  256.                 <interceptor-ref name="execAndWait">  
  257.                     <param name="excludeMethods">input,back,cancel</param>  
  258.                 </interceptor-ref>  
  259.             </interceptor-stack>  
  260.   
  261.             <!-- Deprecated name forms scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 -->  
  262.             <interceptor name="external-ref" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor"/>  
  263.             <interceptor name="model-driven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>  
  264.             <interceptor name="static-params" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>  
  265.             <interceptor name="scoped-model-driven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>  
  266.             <interceptor name="servlet-config" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>  
  267.             <interceptor name="token-session" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>  
  268.   
  269.        </interceptors>  
  270.   
  271.         <default-interceptor-ref name="defaultStack"/>  
  272.     </package>  
  273.   
  274. </struts> 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lm_y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值