Struts中的Action類的工作機制

  所有的Action類都是org.apache.struts.action.Action的子類。Action子類應該覆寫父類的execute()方 法。當ActionForm Bean被創建,并且表單驗證順利通過后,Struts框架就會調用Action類的execute()方法。execute()方法的定義如下:
 
  public ActionForward execute(ActionMapping mapping
                        ActionForm form,
                        HttpServletRequest request,
                        HttpServletResponse response) throws IOException, ServletException;
 
  execute()方法包含一下參數:
  · ActionMapping:包含了這個Action的配置信息,和struts-config.xml文件中的
     <action>元素對應。
  · ActionForm:包含了用戶的表單數據,當Struts框架調用execute()方法時,
     ActionForm中的數據已經通過了表單驗證。
  · HttpServletRequest:當前的HTTP請求對象。
  · HttpServletResponse:當前的HTTP響應對象。
  Action類的execute()方法返回ActionForward對象,它包含了請求轉發路徑信息。



                                      2005年03月31日 1:30 AM