一個form裏多個submit實現不同action method的處理方法
在這裏我使用javascript來處理,實現一個form可以提交不同的action method.如下submit.jsp中一個form內我有三個submit:
submit.jsp
<s:form action="#" name="form1" method="post" theme="simple">
?? <input type="text" value="xxxx" name="userName">
?? <input type="text" value="xxxx" name="password">
?? <s:submit? value="發表"? onclick="subAction('publicMessage.html');"/>
? <s:submit? value="修改"? onclick="subAction('updateMessage.html');"/>
??<s:submit? value="取消"?? onclick="subAction('cancelLeave.html');"/>
?</s:form>
?<script language="javascript">
?? function subAction(formAction)
?? {
?? ? ?var targetForm =? document.form1;
??? ??targetForm.action = formAction;
??? ??targetForm.submit();
?? }
?</script>
其中三個submit按鈕都通過調用一個javascript function來提交form,在調用subAction()時都給它傳遞了一個參數,即struts.xml中給action配置的actionName;
eg:? struts.xml中的配置如下:
<action name="publicMessage" method="publicMessage">
??????????? <result name="success" type="tiles">message.leave.layout</result>
??????? </action>???????
??? <action name="updateMessage" method="updateMessage">
??????????? <result name="success" type="tiles">message.i-leave.layout</result>
??????? </action>
?? <action name="cancelLeave" method="cancelLeave">
??????????? <result name="success" type="tiles">message.leave.layout</result>
??????? </action>
?
2 楼 yexin218 2008-04-26 不错哦,虽然我只会一点点的struct.