Struts2框架中使用包來管理action,避免了Servlet在web.xml中難以管理的與維護的局面.包的作用和java中的類包是非常類似的,它主要用於管理一組業務功能相關的action,在實際應用中,我們應該把一組業務功能相關的action 放在同一個包下.
配置包時必須指定name屬性,該name屬性值可以任意取名,但必須唯一,如果其他包要繼承該包,必須通過該屬性進行引用,包的namespace屬性用於定義該包的命名空間,命名空間作用爲訪問該包下的action路徑的一部分,見示例.namespace屬性可以不配置,如果不指定該屬性,默認的命名空間爲””
通常每個包都應該繼承struts-default包,因爲struts2很多核心功能都是攔截來實現的,如,從請求中把請求參數封閉到action,文件上傳和數據驗證等都是通過攔截器實現的,struts-default定義了這些攔截器和Result類型,可以這麼說,當包繼承了struts-default才能使用struts2提供的核心功能,struts-default包是在struts2-core-2.xx.jar文件中的struts-defalut.xml中定義,struts-default.xml也是struts2默認配置文件,struts2每次都會自動加載struts-default.xml文件.
package還有一個abstract=”true”屬性,指定此包爲抽象包,和抽象類的概念差不多,說明此包只能被其他包繼承,則它裏面不允許包含action元素.
下面貼上struts-default.xml文件的源代碼:
- <?xml version="1.0" encoding="UTF-8" ?>
- <!--
- /*
- * $Id: struts-default.xml 694960 2008-09-13 15:01:00Z rgielen $
- *
- * 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>
- <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 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 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 type="org.apache.struts2.views.TagLibrary" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
- <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 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" />
- <!-- Only have static injections -->
- <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="com.opensymphony.xwork2.validator.ValidatorFileParser" 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" />
- <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"/>
- <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
- <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
- <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
- <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
- <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
- <!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 -->
- <result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
- <result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" />
- </result-types>
- <interceptors>
- <interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/>
- <interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
- <interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/>
- <interceptor name="conversionError" class="org.apache.struts2.interceptor.StrutsConversionErrorInterceptor"/>
- <interceptor name="cookie" class="org.apache.struts2.interceptor.CookieInterceptor"/>
- <interceptor name="createSession" class="org.apache.struts2.interceptor.CreateSessionInterceptor" />
- <interceptor name="debugging" class="org.apache.struts2.interceptor.debugging.DebuggingInterceptor" />
- <interceptor name="externalRef" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor"/>
- <interceptor name="execAndWait" class="org.apache.struts2.interceptor.ExecuteAndWaitInterceptor"/>
- <interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/>
- <interceptor name="fileUpload" class="org.apache.struts2.interceptor.FileUploadInterceptor"/>
- <interceptor name="i18n" class="com.opensymphony.xwork2.interceptor.I18nInterceptor"/>
- <interceptor name="logger" class="com.opensymphony.xwork2.interceptor.LoggingInterceptor"/>
- <interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>
- <interceptor name="scopedModelDriven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>
- <interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/>
- <interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor"/>
- <interceptor name="staticParams" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>
- <interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor"/>
- <interceptor name="servletConfig" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>
- <interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/>
- <interceptor name="timer" class="com.opensymphony.xwork2.interceptor.TimerInterceptor"/>
- <interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/>
- <interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
- <interceptor name="validation" class="org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor"/>
- <interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/>
- <interceptor name="store" class="org.apache.struts2.interceptor.MessageStoreInterceptor" />
- <interceptor name="checkbox" class="org.apache.struts2.interceptor.CheckboxInterceptor" />
- <interceptor name="profiling" class="org.apache.struts2.interceptor.ProfilingActivationInterceptor" />
- <interceptor name="roles" class="org.apache.struts2.interceptor.RolesInterceptor" />
- <!-- Basic stack -->
- <interceptor-stack name="basicStack">
- <interceptor-ref name="exception"/>
- <interceptor-ref name="servletConfig"/>
- <interceptor-ref name="prepare"/>
- <interceptor-ref name="checkbox"/>
- <interceptor-ref name="params"/>
- <interceptor-ref name="conversionError"/>
- </interceptor-stack>
- <!-- Sample validation and workflow stack -->
- <interceptor-stack name="validationWorkflowStack">
- <interceptor-ref name="basicStack"/>
- <interceptor-ref name="validation"/>
- <interceptor-ref name="workflow"/>
- </interceptor-stack>
- <!-- Sample file upload stack -->
- <interceptor-stack name="fileUploadStack">
- <interceptor-ref name="fileUpload"/>
- <interceptor-ref name="basicStack"/>
- </interceptor-stack>
- <!-- Sample model-driven stack -->
- <interceptor-stack name="modelDrivenStack">
- <interceptor-ref name="modelDriven"/>
- <interceptor-ref name="basicStack"/>
- </interceptor-stack>
- <!-- Sample action chaining stack -->
- <interceptor-stack name="chainStack">
- <interceptor-ref name="chain"/>
- <interceptor-ref name="basicStack"/>
- </interceptor-stack>
- <!-- Sample i18n stack -->
- <interceptor-stack name="i18nStack">
- <interceptor-ref name="i18n"/>
- <interceptor-ref name="basicStack"/>
- </interceptor-stack>
- <!-- An example of the params-prepare-params trick. This stack
- is exactly the same as the defaultStack, except that it
- includes one extra interceptor before the prepare interceptor:
- the params interceptor.
- This is useful for when you wish to apply parameters directly
- to an object that you wish to load externally (such as a DAO
- or database or service layer), but can't load that object
- until at least the ID parameter has been loaded. By loading
- the parameters twice, you can retrieve the object in the
- prepare() method, allowing the second params interceptor to
- apply the values on the object. -->
- <interceptor-stack name="paramsPrepareParamsStack">
- <interceptor-ref name="exception"/>
- <interceptor-ref name="alias"/>
- <interceptor-ref name="params"/>
- <interceptor-ref name="servletConfig"/>
- <interceptor-ref name="prepare"/>
- <interceptor-ref name="i18n"/>
- <interceptor-ref name="chain"/>
- <interceptor-ref name="modelDriven"/>
- <interceptor-ref name="fileUpload"/>
- <interceptor-ref name="checkbox"/>
- <interceptor-ref name="staticParams"/>
- <interceptor-ref name="params"/>
- <interceptor-ref name="conversionError"/>
- <interceptor-ref name="validation">
- <param name="excludeMethods">input,back,cancel</param>
- </interceptor-ref>
- <interceptor-ref name="workflow">
- <param name="excludeMethods">input,back,cancel</param>
- </interceptor-ref>
- </interceptor-stack>
- <!-- A complete stack with all the common interceptors in place.
- Generally, this stack should be the one you use, though it
- may do more than you need. Also, the ordering can be
- switched around (ex: if you wish to have your servlet-related
- objects applied before prepare() is called, you'd need to move
- servlet-config interceptor up.
- This stack also excludes from the normal validation and workflow
- the method names input, back, and cancel. These typically are
- associated with requests that should not be validated.
- -->
- <interceptor-stack name="defaultStack">
- <interceptor-ref name="exception"/>
- <interceptor-ref name="alias"/>
- <interceptor-ref name="servletConfig"/>
- <interceptor-ref name="prepare"/>
- <interceptor-ref name="i18n"/>
- <interceptor-ref name="chain"/>
- <interceptor-ref name="debugging"/>
- <interceptor-ref name="profiling"/>
- <interceptor-ref name="scopedModelDriven"/>
- <interceptor-ref name="modelDriven"/>
- <interceptor-ref name="fileUpload"/>
- <interceptor-ref name="checkbox"/>
- <interceptor-ref name="staticParams"/>
- <interceptor-ref name="params">
- <param name="excludeParams">dojo\..*</param>
- </interceptor-ref>
- <interceptor-ref name="conversionError"/>
- <interceptor-ref name="validation">
- <param name="excludeMethods">input,back,cancel,browse</param>
- </interceptor-ref>
- <interceptor-ref name="workflow">
- <param name="excludeMethods">input,back,cancel,browse</param>
- </interceptor-ref>
- </interceptor-stack>
- <!-- The completeStack is here for backwards compatibility for
- applications that still refer to the defaultStack by the
- old name -->
- <interceptor-stack name="completeStack">
- <interceptor-ref name="defaultStack"/>
- </interceptor-stack>
- <!-- Sample execute and wait stack.
- Note: execAndWait should always be the *last* interceptor. -->
- <interceptor-stack name="executeAndWaitStack">
- <interceptor-ref name="execAndWait">
- <param name="excludeMethods">input,back,cancel</param>
- </interceptor-ref>
- <interceptor-ref name="defaultStack"/>
- <interceptor-ref name="execAndWait">
- <param name="excludeMethods">input,back,cancel</param>
- </interceptor-ref>
- </interceptor-stack>
- <!-- Deprecated name forms scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 -->
- <interceptor name="external-ref" class="com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptor"/>
- <interceptor name="model-driven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>
- <interceptor name="static-params" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>
- <interceptor name="scoped-model-driven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>
- <interceptor name="servlet-config" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>
- <interceptor name="token-session" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
- </interceptors>
- <default-interceptor-ref name="defaultStack"/>
- </package>
- </struts>
二、struts2配置文件中常用常量配置列表:
<constant name="struts.i18n.encoding" value="UTF-8" />
指定Web應用的默認編碼集,相當於調用HttpServletRequest的setCharacterEncoding方法
<constant name="struts.action.extension" value="do" />
該屬性指定需要Struts 2處理的請求後綴,該屬性的默認值是action,即所有匹配*.action的請求都由Struts 2處理。 如果用戶需要指定多個請求後綴,則多個後綴之間以英文逗號(,)隔開。
<constant name="struts.serve.static.browserCache " value="false" />
設置瀏覽器是否緩存靜態內容,默認值爲true,開發階段最好false
<constant name="struts.configuration.xml.reload" value="true" />
當struts的配置文件修改後,系統是否自動重新加載該文件,默認值爲false,開發階段最好true
<constant name="struts.devMode" value="true" />
開發模式下設爲true,這樣可以打印出更詳細的錯誤信息
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
動態方法調用,可以解決多個請求對應一個Servlet的問題,後面詳細講解,默認爲true,關閉則設爲false.
這裏只是列舉了一些常用的開關,當然還有許多其他的開關,後面的學習中會逐漸介紹,大家在這裏先了解一下.
以下是從網上摘得的,比較全的一個資料
struts.serve.static.browserCache 該屬性設置瀏覽器是否緩存靜態內容。當應用處於開發階段時,我們希望每次請求都獲得服務器的最新響應,則可設置該屬性爲false。
struts.enable.DynamicMethodInvocation 該屬性設置Struts 2是否支持動態方法調用,該屬性的默認值是true。如果需要關閉動態方法調用,則可設置該屬性爲false。
struts.enable.SlashesInActionNames 該屬性設置Struts 2是否允許在Action名中使用斜線,該屬性的默認值是false。如果開發者希望允許在Action名中使用斜線,則可設置該屬性爲true。
struts.tag.altSyntax 該屬性指定是否允許在Struts 2標籤中使用表達式語法,因爲通常都需要在標籤中使用表達式語法,故此屬性應該設置爲true,該屬性的默認值是true。
struts.devMode該屬性設置Struts 2應用是否使用開發模式。如果設置該屬性爲true,則可以在應用出錯時顯示更多、更友好的出錯提示。該屬性只接受true和flase兩個值,該屬性的默認值是false。通常,應用在開發階段,將該屬性設置爲true,當進入產品發佈階段後,則該屬性設置爲false。
struts.i18n.reload該屬性設置是否每次HTTP請求到達時,系統都重新加載資源文件。該屬性默認值是false。在開發階段將該屬性設置爲true會更有利於開發,但在產品發佈階段應將該屬性設置爲false。
提示 開發階段將該屬性設置了true,將可以在每次請求時都重新加載國際化資源文件,從而可以讓開發者看到實時開發效果;產品發佈階段應該將該屬性設置爲false,是爲了提供響應性能,每次請求都需要重新加載資源文件會大大降低應用的性能。
struts.ui.theme該屬性指定視圖標籤默認的視圖主題,該屬性的默認值是xhtml。
struts.ui.templateDir該屬性指定視圖主題所需要模板文件的位置,該屬性的默認值是template,即默認加載template路徑下的模板文件。
struts.ui.templateSuffix該屬性指定模板文件的後綴,該屬性的默認屬性值是ftl。該屬性還允許使用ftl、vm或jsp,分別對應FreeMarker、Velocity和JSP模板。
struts.configuration.xml.reload該屬性設置當struts.xml文件改變後,系統是否自動重新加載該文件。該屬性的默認值是false。
struts.velocity.configfile該屬性指定Velocity框架所需的velocity.properties文件的位置。該屬性的默認值爲velocity.properties。
struts.velocity.contexts該屬性指定Velocity框架的Context位置,如果該框架有多個Context,則多個Context之間以英文逗號(,)隔開。
struts.velocity.toolboxlocation該屬性指定Velocity框架的toolbox的位置。
struts.url.http.port該屬性指定Web應用所在的監聽端口。該屬性通常沒有太大的用戶,只是當Struts 2需要生成URL時(例如Url標籤),該屬性才提供Web應用的默認端口。
struts.url.https.port該屬性類似於struts.url.http.port屬性的作用,區別是該屬性指定的是Web應用的加密服務端口。
struts.url.includeParams該屬性指定Struts 2生成URL時是否包含請求參數。該屬性接受none、get和all三個屬性值,分別對應於不包含、僅包含GET類型請求參數和包含全部請求參數。
struts.custom.i18n.resources該屬性指定Struts 2應用所需要的國際化資源文件,如果有多份國際化資源文件,則多個資源文件的文件名以英文逗號(,)隔開。
struts.dispatcher.parametersWorkaround 對於某些Java EE服務器,不支持HttpServlet Request調用getParameterMap()方法,此時可以設置該屬性值爲true來解決該問題。該屬性的默認值是false。對於WebLogic、Orion和OC4J服務器,通常應該設置該屬性爲true。
struts.freemarker.manager.classname 該屬性指定Struts 2使用的FreeMarker管理器。該屬性的默認值是org.apache.struts2.views.freemarker.FreemarkerManager,這是Struts 2內建的FreeMarker管理器。
struts.freemarker.wrapper.altMap該屬性只支持true和false兩個屬性值,默認值是true。通常無需修改該屬性值。
struts.xslt.nocache 該屬性指定XSLT Result是否使用樣式表緩存。當應用處於開發階段時,該屬性通常被設置爲true;當應用處於產品使用階段時,該屬性通常被設置爲false。
struts.configuration.files 該屬性指定Struts 2框架默認加載的配置文件,如果需要指定默認加載多個配置文件,則多個配置文件的文件名之間以英文逗號(,)隔開。該屬性的默認值爲struts-default.xml,struts-plugin.xml,struts.xml,看到該屬性值,讀者應該明白爲什麼Struts 2框架默認加載struts.xml文件了。
三、struts2框架中的常識介紹
1、在請求時,路徑後的後綴action可要可不要,即下面的兩種請求都是可以的
http://localhost:8080/Struts2/chapter1/HelloWorld
http://localhost:8080/Struts2/chapter1/HelloWorld.action
2、
<action name="Login">
<result>/WEB-INF/JspPage/chapter1/Login.jsp</result>
</action>
我們發現,當我們請求的路徑爲http://localhost:8080/Struts2/chapter1/Login時,同樣可以實現頁面的跳轉,這是怎麼回事呢?
如果沒有爲action指定class,默認是ActionSupport類<action name="Login">
相當於
<action name="Login" class="com.opensymphony.xwork2.ActionSupport">
如果沒有爲action指定method,默認執行action中的execute()方法
<action name="Login">相當於
<action name="Login" class="com.opensymphony.xwork2.ActionSupport"
method="execute">
如果沒有指定result的name屬性,默認值爲success.
<result>相當於<result name="success">
四、ActionSupport這個類到底是個什麼類,爲什麼自己寫的action都要默認繼承它?
struts2不要求我們自己設計的action類繼承任何的struts基類或struts接口,但是我們爲了方便實現我們自己的action,大多數情況下都會繼承com.opensymphony.xwork2.ActionSupport類,並重寫此類裏的public String execute() throws Exception方法。因爲此類中實現了很多的實用藉口,提供了很多默認方法,這些默認方法包括國際化信息的方法、默認的處理用戶請求的方法等,這樣可以大大的簡化Acion的開發。
下面貼上ActionSupport.action的源代碼
- // Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
- // Jad home page: http://kpdus.tripod.com/jad.html
- // Decompiler options: packimports(3) fieldsfirst ansi space
- // Source File Name: ActionSupport.java
- package com.opensymphony.xwork2;
- import com.opensymphony.xwork2.util.ValueStack;
- import java.io.Serializable;
- import java.util.*;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- // Referenced classes of package com.opensymphony.xwork2:
- // TextProviderFactory, ValidationAwareSupport, Action, Validateable,
- // ValidationAware, TextProvider, LocaleProvider, ActionContext
- public class ActionSupport
- implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable
- {
- protected static Log LOG = LogFactory.getLog(com/opensymphony/xwork2/ActionSupport);
- private final transient TextProvider textProvider = (new TextProviderFactory()).createInstance(getClass(), this);
- private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
- public ActionSupport()
- {
- }
- public void setActionErrors(Collection errorMessages)
- {
- validationAware.setActionErrors(errorMessages);
- }
- public Collection getActionErrors()
- {
- return validationAware.getActionErrors();
- }
- public void setActionMessages(Collection messages)
- {
- validationAware.setActionMessages(messages);
- }
- public Collection getActionMessages()
- {
- return validationAware.getActionMessages();
- }
- /**
- * @deprecated Method getErrorMessages is deprecated
- */
- public Collection getErrorMessages()
- {
- return getActionErrors();
- }
- /**
- * @deprecated Method getErrors is deprecated
- */
- public Map getErrors()
- {
- return getFieldErrors();
- }
- public void setFieldErrors(Map errorMap)
- {
- validationAware.setFieldErrors(errorMap);
- }
- public Map getFieldErrors()
- {
- return validationAware.getFieldErrors();
- }
- public Locale getLocale()
- {
- return ActionContext.getContext().getLocale();
- }
- public String getText(String aTextName)
- {
- return textProvider.getText(aTextName);
- }
- public String getText(String aTextName, String defaultValue)
- {
- return textProvider.getText(aTextName, defaultValue);
- }
- public String getText(String aTextName, String defaultValue, String obj)
- {
- return textProvider.getText(aTextName, defaultValue, obj);
- }
- public String getText(String aTextName, List args)
- {
- return textProvider.getText(aTextName, args);
- }
- public String getText(String key, String args[])
- {
- return textProvider.getText(key, args);
- }
- public String getText(String aTextName, String defaultValue, List args)
- {
- return textProvider.getText(aTextName, defaultValue, args);
- }
- public String getText(String key, String defaultValue, String args[])
- {
- return textProvider.getText(key, defaultValue, args);
- }
- public String getText(String key, String defaultValue, List args, ValueStack stack)
- {
- return textProvider.getText(key, defaultValue, args, stack);
- }
- public String getText(String key, String defaultValue, String args[], ValueStack stack)
- {
- return textProvider.getText(key, defaultValue, args, stack);
- }
- public ResourceBundle getTexts()
- {
- return textProvider.getTexts();
- }
- public ResourceBundle getTexts(String aBundleName)
- {
- return textProvider.getTexts(aBundleName);
- }
- public void addActionError(String anErrorMessage)
- {
- validationAware.addActionError(anErrorMessage);
- }
- public void addActionMessage(String aMessage)
- {
- validationAware.addActionMessage(aMessage);
- }
- public void addFieldError(String fieldName, String errorMessage)
- {
- validationAware.addFieldError(fieldName, errorMessage);
- }
- public String input()
- throws Exception
- {
- return "input";
- }
- public String doDefault()
- throws Exception
- {
- return "success";
- }
- public String execute()
- throws Exception
- {
- return "success";
- }
- public boolean hasActionErrors()
- {
- return validationAware.hasActionErrors();
- }
- public boolean hasActionMessages()
- {
- return validationAware.hasActionMessages();
- }
- public boolean hasErrors()
- {
- return validationAware.hasErrors();
- }
- public boolean hasFieldErrors()
- {
- return validationAware.hasFieldErrors();
- }
- public void clearErrorsAndMessages()
- {
- validationAware.clearErrorsAndMessages();
- }
- public void validate()
- {
- }
- public Object clone()
- throws CloneNotSupportedException
- {
- return super.clone();
- }
- public void pause(String s)
- {
- }
- }