Struts功能詳解——ActionMapping對象

來源:互聯網
上載者:User

在一個web應用中,每個資源都必須通過URI來進行引用。 資源套件括HTML頁面,JSP頁面,和定製動作。為了給定製動作一個 URI或者說路徑,Struts架構提供了一個 ActionMapping對象。

ActionMaping也是Struts的一個核心對象,通常我們不用手寫ActionMapping類,它只需要在設定檔中配置就行。

ActionMapping如何配置:

ActionMapping在設定檔Strtus-config.xml中配置,配置格式如下:

 

<struts-config><action-mappings><actionpath="/login"type="com.bjpowernode.struts.LoginAction"name="loginForm"                scope="request"                ><forwardname="success" path="/login_success.jsp" /><forwardname="error"path="/login_error.jsp"/>                </action></action-mappings></struts-config>

其中<action>標籤是為每一個獨立的action配置,配置他們的訪問方式和存取控制。

<forward>標籤配置action執行完返回以後,需要到達的地方。

其中name scope type分別是actionMapping的一個屬性,它對應著action的需要訪問的位置和資料來源,還有資料範圍。

 

ActionMapping的功能:

ActionMapping的主要功能就是管理Action的資訊和管理Action執行完成以後的ActionForward的資訊。

它將特定請求映射到特定Action的相關資訊儲存ActionMapping中,ActionServelt將ActionMapping傳送到Action類execute()方法,Action將使用ActionMapping的findForward()方法,此方法返回一個指定名稱的ActionForward,這樣Action就完成了本地轉寄。若沒有找到具體的ActionForward,就返回一個null.

 

ActionMapping的方法:

publicExceptionConfig findException(Class type) ,尋找異常對象

public ActionForwardfindForward(String name) 可在映射中動態添加ActionForward:

public String[]findForwards()找到一個Action可以使用的actionForward列表

public ActionForwardgetInputForward() 得到本action的輸入ActionForard.

ActionMapping繼承於org.apache.struts.config.ActionConfig

 

總之,對於ActionMapping來說,起算是一個web控制層的資料字典,這個資料字典裡面存放在Action和ActionForward的資訊,在程式執行的過程中,查閱這個資料字典,然後達到相應的位置,執行完成以後,再查詢這個資料字典,轉寄特定的資訊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.