Struts2中表單與Action傳遞資料三種方式

2021-08-31 08:14:41 字數 733 閱讀 2029

**:

1. action中的屬性與表單中的屬性一致就可以

jsp中的表單

action中的屬性

publicclassloginactionextends actionsupport

publicvoid setusername(string username)

public string getpassword()

publicvoid setpassword(string password)

public string execute()

else}}

2. 使用乙個vo類

在表單中提交的屬性名改為user.username

loginaction中的屬性改為user

publicclassloginactionextends actionsupport

publicvoid setuser(user user)

public string execute()

else}}

3. 使用struts2中的modeldriven資料模式

action類要實現乙個泛型介面,前台表單與1相同

publicclassloginactionextends actionsupport implements modeldriven

else

}public user getmodel()

}

Struts2中表單與Action傳遞資料三種方式

1.action中的屬性與表單中的屬性一致就可以 jsp中的表單 使用者名稱 密碼 form action中的屬性 publicclassloginactionextendsactionsupport publicvoidsetusername string username publicstrin...

struts2 表單驗證

表單驗證有兩種方式,驗證和xml配置驗證器驗證。每種方法都可以設定全域性驗證和單個方法驗證。感覺單個方法用的多一點。例子 使用者註冊,進行驗證。表單如下 struts.xml配置資訊 userpkg extends struts default user class com.huitong.acti...

Struts2提交表單

1 動態方法呼叫,在struts.xml中開啟,實現效果為 constant name struts.enable.dynamicmethodinvocation value true http localhost 8080 struts2 m en submit login.action,動態方法...