Multiple submission of struts2 forms (Annotation Mode)
Assume that a form has several operations (update, delete, create etc.) and can be submitted to action by method. There is a lot of information on the Internet, which describes how to implement multiple submissions through xml configuration. This document is submitted by 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 code:
[Java]
@ ParentPackage (value = "setup ")
Public class MutipleSubmitAction extends BaseAction {
Private String name1;
Private String name2;
Public String getName1 (){
Return name1;
} Www.2cto.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:
The String value returned by the delete () and save () Methods corresponds to the name in annotation @ Result. ValidateSave () is the Save () method verified before the form is submitted.