struts2 表单的多重递交(Annotation方式)
struts2 表单的多重递交(Annotation方式)
假设一个form表单有几个操作(update,delete,create etc.),可以通过method的方式递交到action。网上有很多资料,讲述了通过xml配置的方式实现多重递交的目的。本文通过另一种方式,即annotation的方式递交。
form表单:
[html]
<s:fielderror/>
<s:form action="saveFloorroomdetail" namescapse="/setup">
<table>
<tr>
<td>
<input type="text" name="name1" value="value1" >
</td>
<td>
<input type="text" name="name2" value="value2">
</td>
<tr>
<tr>
<td align="center" colspan="2" height="60">
<s:submit key="button.save" method="save" />
<s:submit key="button.delte" method="delete"/>
</td>
</tr>
</table>
</s:form>
Java代码:
[java]
@ParentPackage(value = "setup")
public class MutipleSubmitAction extends BaseAction{
private String name1;
private String name2;
public String getName1() {
return name1;
} www.zzzyk.com
public void setName1(String name1) {
this.name1 = name1;
}
public String getName2() {
return name2;
}
public void setName2(String name2) {
this.name2 = name2;
}
@Actions( {
@Action(value = "/saveFloorroomdetail", results = {
@Result(location = "detail_result.jsp", name = "success"),
@Result(location = "detail.jsp", name = "input"),
@Result(location = "detail.jsp", name = "delete"),
})
})
public String save(){
System.out.println("invoke save()");
return SUCCESS;
}
public void validateSave(){
System.out.println("validate Save");
}
public String delete(){
System.out.println("invoke delete()");
return "delete";
}
}
Note:
delete()和save()方法返回的String值和annotation @Result中的name对应。validateSave()是表单递交之前验证Save()方法。
补充:软件开发 , Java ,