一個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">

functionsubAction(formAction)

{

vartargetForm=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">

<resultname="success"type="tiles">message.leave.layout</result>

        </action>       

    <action name="updateMessage" class="BugLogAction" method="updateMessage">

<resultname="success"type="tiles">message.i-leave.layout</result>

        </action>

   <action name="cancelLeave" class="BugLogAction" method="cancelLeave">

<resultname="success"type="tiles">message.leave.layout</result>

        </action>

相关推荐