struts-default.xml文件详解

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

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

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

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

[xhtml] view plain copy
  1. xml version="1.0" encoding="UTF-8" ?>  
  2.   
  3.     <bean class="com.opensymphony.xwork2.ObjectFactory" name="xwork" />  
  4.     <bean type="com.opensymphony.xwork2.ObjectFactory" name="struts" class="org.apache.struts2.impl.StrutsObjectFactory" />  
  5.   
  6.     <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="xwork" class="com.opensymphony.xwork2.DefaultActionProxyFactory"/>  
  7.     <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="struts" class="org.apache.struts2.impl.StrutsActionProxyFactory"/>  
  8.   
  9.       
  10.     <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="tiger" class="com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer"/>  
  11.     <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="notiger" class="com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer"/>  
  12.     <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="struts" class="com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer"/>  
  13.   
  14.       
  15.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts" class="org.apache.struts2.dispatcher.mapper.DefaultActionMapper" />  
  16.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="composite" class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />  
  17.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful" class="org.apache.struts2.dispatcher.mapper.RestfulActionMapper" />  
  18.     <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful2" class="org.apache.struts2.dispatcher.mapper.Restful2ActionMapper" />  
  19.   
  20.     <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="struts" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default" optional="true"/>  
  21.     <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default" optional="true" />  
  22.   
  23.       
  24.     <bean type="org.apache.struts2.views.TagLibrary" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />  
  25.   
  26.       
  27.     <bean class="org.apache.struts2.views.freemarker.FreemarkerManager" name="struts" optional="true"/>  
  28.     <bean class="org.apache.struts2.views.velocity.VelocityManager" name="struts" optional="true" />  
  29.   
  30.     <bean class="org.apache.struts2.components.template.TemplateEngineManager" />  
  31.     <bean type="org.apache.struts2.components.template.TemplateEngine" name="ftl" class="org.apache.struts2.components.template.FreemarkerTemplateEngine" />  
  32.     <bean type="org.apache.struts2.components.template.TemplateEngine" name="vm" class="org.apache.struts2.components.template.VelocityTemplateEngine" />  
  33.     <bean type="org.apache.struts2.components.template.TemplateEngine" name="jsp" class="org.apache.struts2.components.template.JspTemplateEngine" />  
  34.   
  35.       
  36.     <bean type="com.opensymphony.xwork2.util.XWorkConverter" name="xwork1" class="com.opensymphony.xwork2.util.XWorkConverter" />  
  37.     <bean type="com.opensymphony.xwork2.util.XWorkConverter" name="struts" class="com.opensymphony.xwork2.util.AnnotationXWorkConverter" />  
  38.     <bean type="com.opensymphony.xwork2.TextProvider" name="xwork1" class="com.opensymphony.xwork2.TextProviderSupport" />  
  39.     <bean type="com.opensymphony.xwork2.TextProvider" name="struts" class="com.opensymphony.xwork2.TextProviderSupport" />  
  40.   
  41.       
  42.     <bean class="com.opensymphony.xwork2.ObjectFactory" static="true" />  
  43.     <bean class="com.opensymphony.xwork2.util.XWorkConverter" static="true" />  
  44.     <bean class="com.opensymphony.xwork2.util.OgnlValueStack" static="true" />  
  45.     <bean class="org.apache.struts2.dispatcher.Dispatcher" static="true" />  
  46.     <bean class="org.apache.struts2.components.Include" static="true" />  
  47.     <bean class="org.apache.struts2.dispatcher.FilterDispatcher" static="true" />  
  48.     <bean class="org.apache.struts2.views.util.ContextUtil" static="true" />  
  49.     <bean class="org.apache.struts2.views.util.UrlHelper" static="true" />  
  50.       
  51.     <package name="struts-default" abstract="true">  
  52.           
  53.         <result-types>  
  54.             <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>  
  55.             <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>  
  56.             <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>  
  57.             <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>  
  58.             <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>  
  59.             <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>  
  60.             <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>  
  61.             <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>  
  62.             <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>  
  63.             <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />  
  64.               
  65.             <result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>  
  66.             <result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" />  
  67.         result-types>  
  68.   
  69.  `  
  70.         <interceptors>  
  71.             <interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/>  
  72.             <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;'>springa>.interceptor.ActionAutowiringInterceptor"/>  
  73.             <interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/>  
  74.             <interceptor name="conversionError" class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"/>  
  75.             <interceptor name="cookie" class="org.apache.struts2.interceptor.CookieInterceptor"/>  
  76.             <interceptor name="createSession" class="org.apache.struts2.interceptor.CreateSessionInterceptor" />  
  77.             <interceptor name="debugging" class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" />  
  78.             <interceptor name="externalRef" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor"/>  
  79.             <interceptor name="execAndWait" class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor"/>  
  80.             <interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/>  
  81.             <interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor"/>  
  82.             <interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor"/>  
  83.             <interceptor name="logger" class="com.opensymphony.xwork2.interceptor.LoggingInterceptor"/>  
  84.             <interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>  
  85.             <interceptor name="scopedModelDriven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>  
  86.             <interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/>  
  87.             <interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor"/>  
  88.             <interceptor name="staticParams" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>  
  89.             <interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor"/>  
  90.             <interceptor name="servletConfig" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>  
  91.             <interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/>  
  92.             <interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"/>  
  93.             <interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/>  
  94.             <interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>  
  95.             <interceptor name="validation" class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/>  
  96.             <interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/>  
  97.             <interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" />  
  98.             <interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" />  
  99.             <interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" />  
  100.             <interceptor name="roles" class="org.apache.struts2.interceptor.RolesInterceptor" />  
  101.   
  102.               
  103.             <interceptor-stack name="basicStack">  
  104.                 <interceptor-ref name="exception"/>  
  105.                 <interceptor-ref name="servletConfig"/>  
  106.                 <interceptor-ref name="prepare"/>  
  107.                 <interceptor-ref name="checkbox"/>  
  108.                 <interceptor-ref name="params"/>  
  109.                 <interceptor-ref name="conversionError"/>  
  110.             interceptor-stack>  
  111.   
  112.               
  113.             <interceptor-stack name="validationWorkflowStack">  
  114.                 <interceptor-ref name="basicStack"/>  
  115.                 <interceptor-ref name="validation"/>  
  116.                 <interceptor-ref name="workflow"/>  
  117.             interceptor-stack>  
  118.   
  119.               
  120.             <interceptor-stack name="fileUploadStack">  
  121.                 <interceptor-ref name="fileUpload"/>  
  122.                 <interceptor-ref name="basicStack"/>  
  123.             interceptor-stack>  
  124.   
  125.               
  126.             <interceptor-stack name="modelDrivenStack">  
  127.                 <interceptor-ref name="modelDriven"/>  
  128.                 <interceptor-ref name="basicStack"/>  
  129.             interceptor-stack>  
  130.   
  131.               
  132.             <interceptor-stack name="chainStack">  
  133.                 <interceptor-ref name="chain"/>  
  134.                 <interceptor-ref name="basicStack"/>  
  135.             interceptor-stack>  
  136.   
  137.               
  138.             <interceptor-stack name="i18nStack">  
  139.                 <interceptor-ref name="i18n"/>  
  140.                 <interceptor-ref name="basicStack"/>  
  141.             interceptor-stack>  
  142.   
  143.               
  144.             <interceptor name="external-ref" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor"/>  
  145.             <interceptor name="model-driven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>  
  146.             <interceptor name="static-params" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>  
  147.             <interceptor name="scoped-model-driven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>  
  148.             <interceptor name="servlet-config" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>  
  149.             <interceptor name="token-session" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>  
  150.   
  151.        interceptors>  
  152.   
  153.         <default-interceptor-ref name="defaultStack"/>  
  154.     package>  
  155.   
  156. struts> 

你可能感兴趣的:(java,Java)