MVC(Model-View-Controller)起源於 Smalltalk-80,現為 Sun 推薦的 J2EE 設計模式。三大核心職責:
處理流程:Controller 接收請求 → 呼叫 Model 處理 → 選擇 View 回應。


ActionServlet(單一入口 Servlet)ActionMapping 對應請求路徑至具體 Action 處理器struts-config.xml 定義所有映射關係Action:開發者繼承 org.apache.struts.action.Action,封裝具體處理邏輯,呼叫業務 BeanActionForm:表單資料封裝,屬性對應 HTML 表單欄位,支援驗證與重置<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:form action="/information/budgetinfoadd" enctype="multipart/form-data">
<html:select property="infoType" styleClass="input2">
<html:options collection="TypeList" property="id" labelProperty="typeName"/>
</html:select>
</html:form>
關鍵點:action 指向 Action 路徑,<html:form> 自動封裝表單資料至對應 ActionForm。
public final class BudgetInfoAddForm extends ActionForm {
private String infoType, title, content;
private FormFile infoFile;
// getter/setter 略
public void reset(ActionMapping mapping, HttpServletRequest request) {
title = content = null; infoFile = null;
}
}
BudgetInfoAddAction - 錄入BudgetInfoContentAction - 查詢BudgetInfoUpdateAction - 修改BudgetInfoDelAction - 刪除web.xml:定義 ActionServlet、標籤庫、Filter 等struts-config.xml:串聯 MVC 三層,定義 Action Mapping、Form Bean、ForwardStruts 以模組化元件、靈活擴充、標籤庫加速開發,顯著降低企業級 Web 應用建構複雜度,提升可維護性與擴充性。