一:通常是用來取網頁中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();}