四、 配置FormBean
<form-bean / >用來定義將要綁定到Action的FormBean的實例。語法如下:
<form-beans>
<form-bean name="name used to uniquely identify a FormBean"
type=”fully qualified class name of FormBean"/>
</form-beans>
例:
<form-beans>
<form-bean name="lookupForm" type="wiley.LookupForm" />
</form-beans>
五、 配置全局轉發
全局轉發可以定義幾個<forward/>子元素,struts首先會在<action-mappings>元素中找對應的<forward>,若找不到,則到全局轉發配置中找。語法如下:
<global-forwards>
<forward name="unique target identifier"
path="context-relative path to targetted resource "/>
</global-forwards>
除了name及path屬性之外,還有一個redirect屬性,如果redirect設爲true的時候,則用HttpServletResponse.sendRedirect()方法,否則用RequestDispatcher.forward()方法,缺省爲false。
注:如果爲true,則用HttpServletResponse.sendRedirect()方法,此時存儲在原來的HttpServletRequest中的值將會丟失。
例子:
<global-forwards>
<forward name="success" path="/welcome.jsp"/>
<forward name="failure" path="/index.jsp"/>
</global-forwards>
六、 配置<action-mappings>
它可以定義幾個<action / >子元素,它主要是定義Action實例到ActionServlet類中,語法如下:
<action-mappings>
<action path="context-relative path mapping action to a request"
type="fully qualified class name of the Action class"
name="the name of the form bean bound to this Action">
<forward name="forwardname1" path="context-relative
<forward name="forwardname2" path="context-relative path"/>
</action>
</action-mappings>
<action/>屬性及其描述信息如下:
屬 性 描 述 信 息
Path 在瀏覽器的URL中輸入的字符(必須的)
Type 連結到本映射的Action的全稱(可選的)
Name 與本操作關聯的Action Bean在<form-bean/>中定義name名(可選的)
Scope 指定ActionForm Bean的作用域(session和request),缺省爲session。(可選的)
Input 當Bean發生錯誤時返回的控制。(可選的)
ClassName 指定一個調用這個Action類的ActionMapping類的全名。缺省用org.apache.struts.action.ActionMapping,(可選的)
Forward 指定處理相應請求所對應的JSP頁面。(可選的)
Include 如果沒有forward的時候,它起forward的作用。(可選的)
Validate 若爲true,則會調用ActionForm的validate()方法,否則不調用,缺省爲true。(可選的)
例子:
<action-mappings>
<action path="/lookupAction"
type="wiley.LookupAction"
name="LookupForm"
scope="request"
validate="true"
input="/index.jsp">
<forward name="success" path="/quote.jsp"/>
<forward name="faliue" path="/index.jsp"/>
</action>
</action-mappings>v