在index.jsp中設計表單(只包含<body>標簽內的內容):
<body>
??<h4>請輸入你的基本信息</h4>
????<formname="infoForm"action="go.action"method="POST">
????????姓名:<inputtype="text"name="person.name"/><br>
????????性別:<selectname="person.sex">
?????????????<optionvalue="男">男</option>
?????????????<optionvalue="女">女</option>
????????</select><br>
????????地址:<inputtype="text"name="person.address"/><br>
????????電話:<inputtype="text"name="person.phone"/><br>
????????<inputtype="submit"value="提交"/> <inputtype="reset"value="重置"/><br>
????</form>
??</body>
創建com.action包,其中寫MyAction.java文件,注意它是ActionSupport類的子類。ActionSupport類在com.opensymphony.xwork2.ActionSupport中。
packagecom.action;
importcom.bean.Person;
importcom.opensymphony.xwork2.ActionSupport;
publicclassMyActionextendsActionSupport {
????privatePersonperson;
????@Override
????publicString execute()throwsException {
???????//TODOAuto-generated method stub
???????returnSUCCESS;
????}
????publicPerson getPerson() {
???????returnperson;
????}
????publicvoidsetPerson(Person person) {
???????if(person ==null) person =newPerson();
???????this.person= person;
????}
}
posted on 2007-09-24 14:48
jadmin 閱讀(96)
評論(0) 編輯 收藏