首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 相關知識

Struts 文件上傳實戰(三):MaintainForm 表單 Bean 實現

     編輯:Java 相關知識

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() 可在表單重用時清空檔案引用。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved