自定義ActionForward
構建ActionForward對象
ActionForward類提供了下面五種構造器:
public ActionForward()
public ActionForward(String path)
public ActionForward(String path, boolean redirect)
public ActionForward(String name, String path, boolean redirect)
public ActionForward(String name, String path, boolean redirect, boolean contextRelative)
雖然這些構造器是不需要說明的,但我們應該注意下面幾點。在這些構造器中,第二種可能是最常用的。後四種構造器中的path參數表示的是到目的資源的路徑。後三種構造器中的redirect布爾值表示的是是否執行了一個重定向(redirect)。(缺省情況下,這個值設置爲false,因爲redirect比forward慢。)最後,第五個構造器中的contextRelative布爾值表示該路徑是否應該是context-relative的,而不是module-relative的。
同樣,一個ActionForward實例也可以有一個邏輯名稱,你可以用這個名稱來查找與一個特殊的ActionMapping對象相關的實例。(參見本系列第四部分關於ActionMapping的講述。)
學習ActionForward類的方法
ActionForward類定義了三個保護字段——name、path和redirect——它們構成了ActionForward的三個屬性。ActionForward類提供getter和setter方法來從這些字段讀值、給這些字段賦值。這些方法是不需要說明的,定義如下:
public boolean getContextRelative()
public void setContextRelative(boolean contextRelative)
public String getName()
public void setName(String name)
public String getPath()
public void setPath(String path)
public boolean getRedirect()
public void setRedirect(boolean redirect)
除此之外,ActionForward類還重載了toString方法並返回:"ActionForward[" + name + "]"其中name是名稱字段。
最後,還有一個freeze方法,它固定了一個組件的配置。