struts1.x中ActionForm的作用

來源:互聯網
上載者:User

一:通常是用來取網頁中html標籤的值,概念性的東西就不說了。通常就是ActionForm中設定變數屬性和相應得getset方法。之後再action中調用actionFrom得到頁面的值。我們只需寫好actionForm,struts1會自動把頁面的相應值匹配上。比如:頁面上有2個標籤,我們需要在action中得到這個2個標籤的值建立一個包,包名叫com,TestForm和TestAction都建在com包下test.html:

<form action="xx.do"><input type="text" name="username" /><input type="password" name="password" /><input type="submit" value="提交" /></form>

 

二:在struts-config.xml中的配置:

<struts-config> <form-beans>      <form-bean name="newsForm" type="com.NewsForm" />
      </form-beans><action path="/TestAction" name="newsForm" type="com.TestAction"></action>

三:TestForm.java:

String username;String password;public static setUsername(String username){this.username=username;}public String getUsername(){return username;}public setPassword(String password){this.password=password;}public String getPassword(){return password;}

四:TestAction.java:

public ActionForward execute(ActionMapping mapping, ActionForm form,   HttpServletRequest request, HttpServletResponse response) {TestForm tf=(TestForm)form;tf.getPassword();tf.getUsername();}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.