1)预定义拦截器

  Struts2有默认的拦截器配置,也就是说,虽然我们没有主动去配置任何关于拦截器的东西,但是Struts2会使用默认引用的拦截器。由于Struts2的默认拦截器声明和引用都在这个Struts-default.xml里面,因此我们需要到这个文件的struts-default包里去看一下。定义如下:

  1         <interceptors>
  2             <interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/>
  3             <interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
  4             <interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/>
  5             <interceptor name="conversionError" class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"/>
  6             <interceptor name="cookie" class="org.apache.struts2.interceptor.CookieInterceptor"/>
  7             <interceptor name="cookieProvider" class="org.apache.struts2.interceptor.CookieProviderInterceptor"/>
  8             <interceptor name="clearSession" class="org.apache.struts2.interceptor.ClearSessionInterceptor" />
  9             <interceptor name="createSession" class="org.apache.struts2.interceptor.CreateSessionInterceptor" />
 10             <interceptor name="debugging" class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" />
 11             <interceptor name="execAndWait" class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor"/>
 12             <interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/>
 13             <interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor"/>
 14             <interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor"/>
 15             <interceptor name="logger" class="com.opensymphony.xwork2.interceptor.LoggingInterceptor"/>
 16             <interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>
 17             <interceptor name="scopedModelDriven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>
 18             <interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/>
 19             <interceptor name="actionMappingParams" class="org.apache.struts2.interceptor.ActionMappingParametersInteceptor"/>
 20             <interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor"/>
 21             <interceptor name="staticParams" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>
 22             <interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor"/>
 23             <interceptor name="servletConfig" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>
 24             <interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"/>
 25             <interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/>
 26             <interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
 27             <interceptor name="validation" class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/>
 28             <interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/>
 29             <interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" />
 30             <interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" />
 31             <interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" />
 32             <interceptor name="roles" class="org.apache.struts2.interceptor.RolesInterceptor" />
 33             <interceptor name="annotationWorkflow" class="com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptor" />
 34             <interceptor name="multiselect" class="org.apache.struts2.interceptor.MultiselectInterceptor" />
 35             <interceptor name="deprecation" class="org.apache.struts2.interceptor.DeprecationInterceptor" />
 36 
 37             <!-- Basic stack -->
 38             <interceptor-stack name="basicStack">
 39                 <interceptor-ref name="exception"/>
 40                 <interceptor-ref name="servletConfig"/>
 41                 <interceptor-ref name="prepare"/>
 42                 <interceptor-ref name="checkbox"/>
 43                 <interceptor-ref name="multiselect"/>
 44                 <interceptor-ref name="actionMappingParams"/>
 45                 <interceptor-ref name="params">
 46                     <param name="excludeParams">^class\..*,^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
 47                 </interceptor-ref>
 48                 <interceptor-ref name="conversionError"/>
 49                 <interceptor-ref name="deprecation"/>
 50             </interceptor-stack>
 51 
 52             <!-- Sample validation and workflow stack -->
 53             <interceptor-stack name="validationWorkflowStack">
 54                 <interceptor-ref name="basicStack"/>
 55                 <interceptor-ref name="validation"/>
 56                 <interceptor-ref name="workflow"/>
 57             </interceptor-stack>
 58 
 59             <!-- Sample file upload stack -->
 60             <interceptor-stack name="fileUploadStack">
 61                 <interceptor-ref name="fileUpload"/>
 62                 <interceptor-ref name="basicStack"/>
 63             </interceptor-stack>
 64 
 65             <!-- Sample model-driven stack  -->
 66             <interceptor-stack name="modelDrivenStack">
 67                 <interceptor-ref name="modelDriven"/>
 68                 <interceptor-ref name="basicStack"/>
 69             </interceptor-stack>
 70 
 71             <!-- Sample action chaining stack -->
 72             <interceptor-stack name="chainStack">
 73                 <interceptor-ref name="chain"/>
 74                 <interceptor-ref name="basicStack"/>
 75             </interceptor-stack>
 76 
 77             <!-- Sample i18n stack -->
 78             <interceptor-stack name="i18nStack">
 79                 <interceptor-ref name="i18n"/>
 80                 <interceptor-ref name="basicStack"/>
 81             </interceptor-stack>
 82 
 83             <!-- An example of the paramsPrepareParams trick. This stack
 84                  is exactly the same as the defaultStack, except that it
 85                  includes one extra interceptor before the prepare interceptor:
 86                  the params interceptor.
 87 
 88                  This is useful for when you wish to apply parameters directly
 89                  to an object that you wish to load externally (such as a DAO
 90                  or database or service layer), but can't load that object
 91                  until at least the ID parameter has been loaded. By loading
 92                  the parameters twice, you can retrieve the object in the
 93                  prepare() method, allowing the second params interceptor to
 94                  apply the values on the object. -->
 95             <interceptor-stack name="paramsPrepareParamsStack">
 96                 <interceptor-ref name="exception"/>
 97                 <interceptor-ref name="alias"/>
 98                 <interceptor-ref name="i18n"/>
 99                 <interceptor-ref name="checkbox"/>
100                 <interceptor-ref name="multiselect"/>
101                 <interceptor-ref name="params">
102                     <param name="excludeParams">^class\..*,^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
103                 </interceptor-ref>
104                 <interceptor-ref name="servletConfig"/>
105                 <interceptor-ref name="prepare"/>
106                 <interceptor-ref name="chain"/>
107                 <interceptor-ref name="modelDriven"/>
108                 <interceptor-ref name="fileUpload"/>
109                 <interceptor-ref name="staticParams"/>
110                 <interceptor-ref name="actionMappingParams"/>
111                 <interceptor-ref name="params">
112                     <param name="excludeParams">^class\..*,^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
113                 </interceptor-ref>
114                 <interceptor-ref name="conversionError"/>
115                 <interceptor-ref name="validation">
116                     <param name="excludeMethods">input,back,cancel,browse</param>
117                 </interceptor-ref>
118                 <interceptor-ref name="workflow">
119                     <param name="excludeMethods">input,back,cancel,browse</param>
120                 </interceptor-ref>
121             </interceptor-stack>
122 
123             <!-- A complete stack with all the common interceptors in place.
124                  Generally, this stack should be the one you use, though it
125                  may do more than you need. Also, the ordering can be
126                  switched around (ex: if you wish to have your servlet-related
127                  objects applied before prepare() is called, you'd need to move
128                  servletConfig interceptor up.
129 
130                  This stack also excludes from the normal validation and workflow
131                  the method names input, back, and cancel. These typically are
132                  associated with requests that should not be validated.
133                  -->
134             <interceptor-stack name="defaultStack">
135                 <interceptor-ref name="exception"/>
136                 <interceptor-ref name="alias"/>
137                 <interceptor-ref name="servletConfig"/>
138                 <interceptor-ref name="i18n"/>
139                 <interceptor-ref name="prepare"/>
140                 <interceptor-ref name="chain"/>
141                 <interceptor-ref name="scopedModelDriven"/>
142                 <interceptor-ref name="modelDriven"/>
143                 <interceptor-ref name="fileUpload"/>
144                 <interceptor-ref name="checkbox"/>
145                 <interceptor-ref name="multiselect"/>
146                 <interceptor-ref name="staticParams"/>
147                 <interceptor-ref name="actionMappingParams"/>
148                 <interceptor-ref name="params">
149                     <param name="excludeParams">^class\..*,^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
150                 </interceptor-ref>
151                 <interceptor-ref name="conversionError"/>
152                 <interceptor-ref name="validation">
153                     <param name="excludeMethods">input,back,cancel,browse</param>
154                 </interceptor-ref>
155                 <interceptor-ref name="workflow">
156                     <param name="excludeMethods">input,back,cancel,browse</param>
157                 </interceptor-ref>
158                 <interceptor-ref name="debugging"/>
159                 <interceptor-ref name="deprecation"/>
160             </interceptor-stack>
161 
162             <!-- The completeStack is here for backwards compatibility for
163                  applications that still refer to the defaultStack by the
164                  old name -->
165             <interceptor-stack name="completeStack">
166                 <interceptor-ref name="defaultStack"/>
167             </interceptor-stack>
168 
169             <!-- Sample execute and wait stack.
170                  Note: execAndWait should always be the *last* interceptor. -->
171             <interceptor-stack name="executeAndWaitStack">
172                 <interceptor-ref name="execAndWait">
173                     <param name="excludeMethods">input,back,cancel</param>
174                 </interceptor-ref>
175                 <interceptor-ref name="defaultStack"/>
176                 <interceptor-ref name="execAndWait">
177                     <param name="excludeMethods">input,back,cancel</param>
178                 </interceptor-ref>
179             </interceptor-stack>
180 
181        </interceptors>
182 
183         <default-interceptor-ref name="defaultStack"/>
View Code

相关文章: