【正文】
某些 人可能工作于 /customer Actio。這通常是 /do/*或者 *.do,但是其他相似的樣式也可以使用。 They just happen to 使用 the same characters that we are 使用 d to seeing in hierarchical 文件 systems. 當(dāng)然 , 這對處理 ActionMapping仍然是有幫助的,就象他們是一個(gè)層次關(guān)系或者在同一個(gè) 文 件夾 .下的相關(guān)命令組的一部分。 path 可以包括反 斜杠和擴(kuò)展名 如果他引用到一個(gè)文件系統(tǒng) —但他們都只是一 個(gè)單一名稱的一部分。它是一個(gè)對 ActionMapping的虛擬引用。 path屬性 ActionMapping URI,或者 path,對用戶來說就象 web server上的一個(gè)文件。在一個(gè)應(yīng)用中僅有一個(gè) mapping 可定義為缺省 unknown mapping。 prefix 用來匹配請求參數(shù)名稱到 form bean 屬性名稱的前綴,如果有 suffix 在組裝 Actionform bean屬性時(shí),用來匹配請求參數(shù)名稱的后綴,如果有。如果它是 bean39。 parameter 通用配置參數(shù),用來向 ActionMapping選定的 Action傳遞額外的參數(shù)信息。 roles 可以存取該 mapping的安全角色列表 . scope 范圍(請求或會話)識別符,如果有,與該 mapping相關(guān)的 forma Bean在其中創(chuàng)建 validate 如果與該 mapping相關(guān)的 form bean的 validate 方法 (如果有 )要被調(diào)用,設(shè)置為 true. input 輸入表單的上下文相關(guān)的路徑,如果校驗(yàn)錯(cuò)誤,控制應(yīng)該被返回到該表單。這不是類名稱。 或 type 可選,表明一個(gè) ,在實(shí)例化這個(gè) mapping Struts In Action 時(shí)使用。 或 include 上下文相關(guān)的資源路徑,通過一個(gè) include服務(wù)這個(gè)請求。 (API mand) forward 上下文相關(guān)的資源路徑,通過一個(gè) forward服務(wù)這個(gè)請求。當(dāng)和其他配置組件一起,開 發(fā)人員可以擴(kuò)展 ActionMapping to 提 供附加的屬性。 ActionMapping類可以工作在兩個(gè)版本下。 ActionMapping 已經(jīng)不推薦,但后繼版本中類的層次還沒有決定。 在本章,我們將詳細(xì)討論 ActionMapping 屬性,并展示他們?nèi)绾斡兄谠O(shè)計(jì) Struts 應(yīng)用的流 程。如果你想知道如何編寫一 個(gè)新的 Struts 應(yīng)用,也請從 ActionMapping開始。 ActionMapping表達(dá)了 Struts 應(yīng)用的核心設(shè)計(jì)。 ActionMapping工作起來就像是 servlet的一個(gè)路由聯(lián)絡(luò)?;蛘咭苍S它需要組裝并且校驗(yàn) 一個(gè) ActionForm bean。 ActionServlet 使用 ActionMapping bean 17 來決定接下來該做什么。 ActionMapping 目錄 ActionMapping將對 Struts 應(yīng)用有效的業(yè)務(wù)邏輯進(jìn)行編目。 [Go4]. ActionMapping通常通過 Struts 配置文件創(chuàng)建。 Struts In Action DEFINITION 裝飾器模式( decorator pattern)的意圖是為一個(gè)對象動態(tài)的附加上額外的職責(zé)和功能。所以本質(zhì)上來說, Action 是一個(gè)裝飾器( decorator [Go4])。原本 , ActionMapping 對象用來擴(kuò)展 Action 對象 而不是 Action 類。 當(dāng)一個(gè) 請求到來, ActionServlet 使用 path 屬性來選擇對應(yīng)的 ActionMapping。 這樣, ActionMapping出場了! ActionMapping bean ActionMapping () 描述了框架是如何處 理每一離散的業(yè)務(wù)操作 (或 action)。但 是要讓它能工作,我們可能需要向?qū)ο髠鬟f一些配置參數(shù),以便和每個(gè)操作一起使用。 同時(shí),在實(shí)際應(yīng)用中,許多業(yè)務(wù)操作都以相似的方式來進(jìn)行處理。我們和 Web瀏覽器進(jìn)行通信能使用的唯一途徑是 HTTP 請求和 URI。用 servlet 接受 請求并路由到一個(gè)處理器(稱為前端 控制器模式 [Go3])。處理業(yè)務(wù)操作是 servlet代表其它組件干的 事情。簡單的創(chuàng)建很多 servlet并沒有 什么性能優(yōu)勢。因?yàn)?servlet是多線 程的,實(shí)例化這么多 servlet 顯然不是使用服務(wù)器資源的最好方式。某些應(yīng)用通過給每個(gè)業(yè)務(wù)操作映射一個(gè)Servlet來實(shí) 現(xiàn) Model 2。 web應(yīng)用部署描述符 () 讓我們可以映射一個(gè) URL模板給一個(gè) servlet。在 Model 2下,我們 從調(diào)用一個(gè) servlet開始。 } 202 CHAPTER 7 Designing with ActionMappings Properties file. While slightly more plicated than the others, another popular approach to providing multiple parameters to an ActionMapping is with a standard Properties files (). Depending on your needs, the Properties file could be stored in an absolute location in your file system or anywhere on your application’s CLASSPATH. The Commons Scaffold package [ASF, Commons] provides a ResourceUtils package () with methods for loading a Properties file from an absolute location or from your application’s CLASSPATH. The attribute property From time to time, you may need to store two copies of the same ActionForm in the same context at the same time. This most often happens when ActionForms are being stored in the session context as part of a workflow. To keep their names from conflicting, you can use the attribute property to give one ActionForm bean a different name. 11 An alternative approach is to define another ActionForm bean in the configuration, using the same type but under a different name. The prefix and suffix properties Like attribute, the prefix and suffix properties can be used to help avoid naming conflicts in your application. When specified, these switches enable a prefix or suffix for the property name, forming an alias when it is populated from the request. If the prefix this was specified, then thisName=McClanahan bees equivalent to name=McClanahan for the purpose of populating the ActionForm. Either or both parameters would call getName(McClanahan)。 String[] parameters = new String[()]。)。 Multiple parameters While multiple parameters are not supported by the standard ActionMappings class, there are some easy ways to implement this, including using HttpUtils, a StringTokenizer, or a Properties file (). HttpUtils. Although deprecated as of the Servlet API specification, the HttpUtils package () provides a static method that parses any string as if it were a query string and returns a Hashtable 10 (): Hashtable parameters = parseQueryString(parameter)。 本科畢業(yè)設(shè)計(jì) ( 論文 ) 外 文 翻譯(附外文 原文 ) 系 ( 院 ): 信息科學(xué)與工程學(xué)院 課題名稱 : 學(xué)生信息管理系統(tǒng) 專業(yè) (方向 ): 計(jì)算機(jī)科學(xué)與技術(shù)(應(yīng)用) 班 級: 計(jì)本 061 班 學(xué) 生: 指導(dǎo)教師 : 日 期 : 1 Enter ActionMappings The Model 2 architecture (see chapter 1) encourages us to use servlets and Java Server Pages in the same application. Under Model 2, we start by calling a servlet. The servlet handles the business logic and directs control to the appropriate page to plete the response. The web application deployment descriptor () lets us map a URL pattern to a servlet. This can be a general pattern, like *.do, or a specific path, like . Some applications implement Model 2 by mapping a servlet to each business operation. This approach works, but many applications involve dozens or hundreds of business operations. Since servlets are multithreaded, instantiating so manyservlets is not the best use of server resources. Servlets are designed to handle any number of parallel requests. There is no performance benefit in simply creating more and more servlets. The servlet’s primary job is to interact with the container and HTTP. Handling a business operation is something that a servlet could delegate to another ponent. Struts does this by having the ActionServlet delegate the business operation to an object. Using a servlet to receive a request and route it to a handler is known as the Front Controller pattern [Go3]. Of course, simply de