關於Struts2,前台表單傳值到後台方式

2021-07-15 14:35:08 字數 625 閱讀 2715

正在學習struts2框架,今天做了乙個demo,登入功能,前端from表單提交賬號密碼資訊。

web.xml配置檔案裡

struts2

org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter

struts2

*.action

在action類裡如下:

private string userid;

private string userpw;

@override

public string execute() throws exception

return "fail";

}public string getuserid()

public void setuserid(string userid)

public string getuserpw()

public void setuserpw(string userpw)

在控制台列印輸出賬號密碼,剛開始的時候一直顯示為null。

把前端from表單屬性裡的action=「login」 改為action=「login.action」,就行了。

struts2 Action獲取表單傳值的三種方法

1.通過屬性驅動式 jsp action 直接通過get set方法獲取 public class sysaction extends actionsupport public string getusername public void setusername string username 2....

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,動態方法...