在這裏我使用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="發表" οnclick="subAction('publicMessage.html');"/>
<s:submit value="修改" οnclick="subAction('updateMessage.html');"/>
<s:submit value="取消" οnclick="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" class="BugLogAction" method="publicMessage">
<result name="success" type="tiles">message.leave.layout</result>
</action>
<action name="updateMessage" class="BugLogAction" method="updateMessage">
<result name="success" type="tiles">message.i-leave.layout</result>
</action>
<action name="cancelLeave" class="BugLogAction" method="cancelLeave">
<result name="success" type="tiles">message.leave.layout</result>
</action>