struts-default.xml檔案詳解

來源:互聯網
上載者:User

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代碼的詳細解釋如下: [xhtml] view plain copy <?xml version="1.0" encoding="UTF-8" ?>   <!--   /*    * $Id: struts-default.xml 559615 2007-07-25 21:25:25Z apetrelli $    *    * Licensed to the Apache Software Foundation (ASF) under one    * or more contributor license agreements.  See the NOTICE file    * distributed with this work for additional information    * regarding copyright ownership.  The ASF licenses this file    * to you under the Apache License, Version 2.0 (the    * "License"); you may not use this file except in compliance    * with the License.  You may obtain a copy of the License at    *    *  http://www.apache.org/licenses/LICENSE-2.0    *    * Unless required by applicable law or agreed to in writing,    * software distributed under the License is distributed on an    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY    * KIND, either express or implied.  See the License for the    * specific language governing permissions and limitations    * under the License.    */   -->      <!DOCTYPE struts PUBLIC       "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"       "http://struts.apache.org/dtds/struts-2.0.dtd">      <struts>       <!--struts2中工廠bean的定義-->       <bean class="com.opensymphony.xwork2.ObjectFactory" name="xwork" />       <bean type="com.opensymphony.xwork2.ObjectFactory" name="struts" class="org.apache.struts2.impl.StrutsObjectFactory" />          <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="xwork" class="com.opensymphony.xwork2.DefaultActionProxyFactory"/>       <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="struts" class="org.apache.struts2.impl.StrutsActionProxyFactory"/>          <!--類型檢測bean的定義-->       <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="tiger" class="com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer"/>       <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="notiger" class="com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer"/>       <bean type="com.opensymphony.xwork2.util.ObjectTypeDeterminer" name="struts" class="com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer"/>          <!--檔案上傳bean的定義-->       <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts" class="org.apache.struts2.dispatcher.mapper.DefaultActionMapper" />       <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="composite" class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />       <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful" class="org.apache.struts2.dispatcher.mapper.RestfulActionMapper" />       <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful2" class="org.apache.struts2.dispatcher.mapper.Restful2ActionMapper" />          <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="struts" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default" optional="true"/>       <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default" optional="true" />          <!--標籤庫bean的定義-->       <bean type="org.apache.struts2.views.TagLibrary" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />          <!--一些常用視圖bean的定義-->       <bean class="org.apache.struts2.views.freemarker.FreemarkerManager" name="struts" optional="true"/>       <bean class="org.apache.struts2.views.velocity.VelocityManager" name="struts" optional="true" />          <bean class="org.apache.struts2.components.template.TemplateEngineManager" />       <bean type="org.apache.struts2.components.template.TemplateEngine" name="ftl" class="org.apache.struts2.components.template.FreemarkerTemplateEngine" />       <bean type="org.apache.struts2.components.template.TemplateEngine" name="vm" class="org.apache.struts2.components.template.VelocityTemplateEngine" />       <bean type="org.apache.struts2.components.template.TemplateEngine" name="jsp" class="org.apache.struts2.components.template.JspTemplateEngine" />          <!--類型轉換bean的定義-->       <bean type="com.opensymphony.xwork2.util.XWorkConverter" name="xwork1" class="com.opensymphony.xwork2.util.XWorkConverter" />       <bean type="com.opensymphony.xwork2.util.XWorkConverter" name="struts" class="com.opensymphony.xwork2.util.AnnotationXWorkConverter" />       <bean type="com.opensymphony.xwork2.TextProvider" name="xwork1" class="com.opensymphony.xwork2.TextProviderSupport" />       <bean type="com.opensymphony.xwork2.TextProvider" name="struts" class="com.opensymphony.xwork2.TextProviderSupport" />          <!--Struts2中一些可以靜態注入的bean,也就是不需要執行個體化的-->       <bean class="com.opensymphony.xwork2.ObjectFactory" static="true" />       <bean class="com.opensymphony.xwork2.util.XWorkConverter" static="true" />       <bean class="com.opensymphony.xwork2.util.OgnlValueStack" static="true" />       <bean class="org.apache.struts2.dispatcher.Dispatcher" static="true" />       <bean class="org.apache.struts2.components.Include" static="true" />       <bean class="org.apache.struts2.dispatcher.FilterDispatcher" static="true" />       <bean class="org.apache.struts2.views.util.ContextUtil" static="true" />       <bean class="org.apache.struts2.views.util.UrlHelper" static="true" />       <!--定義Struts2預設包-->       <package name="struts-default" abstract="true">           <!--結果類型的種類-->           <result-types>               <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>               <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>               <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>               <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>               <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.