MaintainForm.java 完整代碼
package tester.business.maitain;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import org.apache.struts.upload.*;
public class MaintainForm extends ActionForm {
private Trainplan trainPlan = new Trainplan();
private FormFile theFile1;
private FormFile theFile2;
private FormFile theFile3;
public String getP_title() { return trainPlan.getP_title(); }
public void setP_title(String p_title) { trainPlan.setP_title(p_title); }
public void setTrainPlan(Trainplan trainP) { this.trainPlan = trainP; }
public Trainplan getTrainPlan() { return this.trainPlan; }
public void setTheFile1(FormFile theFile1) { this.theFile1 = theFile1; }
public FormFile getTheFile1() { return theFile1; }
public void setTheFile2(FormFile theFile2) { this.theFile2 = theFile2; }
public FormFile getTheFile2() { return theFile2; }
public void setTheFile3(FormFile theFile3) { this.theFile3 = theFile3; }
public FormFile getTheFile3() { return theFile3; }
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
return null; // 可在此加入服務端驗證邏輯
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
// 重置表單狀態
}
}
設計說明
- 封裝
Trainplan 領域物件,透過委派暴露其屬性(如 getP_title()),支援 JSP 巢狀屬性綁定 trainPlan.p_title。
- 三個
FormFile 屬性對應三個附件上傳欄位。
validate() 留空,實際專案可檢查必填欄位、檔案大小、類型等。
reset() 可在表單重用時清空檔案引用。