struts2中怎样实现一个表单两个action
我想在一个表单中同时实现添加和更新的功能,应该怎么写代码?
//form表单
<form id="form2" name="form2" action="">
<tr>
<td
<center>
<input name="addButton" type="submit" value="添加" />
<input name="refreshButton" type="submit" value="更新" />
</center>
</td>
</tr>
</table>
</form>
//struts.xml
<package name="1" extends="struts-default">
<action name="search" class="rtcrud.SearchInfo">
<result name="success">/showInfo.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
------解决方案--------------------你不能把添加和更新从前端传参数至后台,action根据判断去执行(具体是添加还是更新)?
------解决方案--------------------<input name="addButton" type="submit" value="添加" onlick="document.form2.action='url1';submit()"/>
<input name="refreshButton" type="submit" value="更新" onlick="document.form2.action='url2';submit()"/>
思路这样的,点button时动态改变form的action值
------解决方案--------------------表单:
<form action="baocun.action" method="post">
<input type="submit" value="添加"/>
</form>
<hr>
<b>用户密码修改:</b><br>
<form action="xiugai.action" method="post">
<input type="submit" value="更新">
</form>
struts.xml:
<action name="baocun" class="com.wiew.UserView" method="execute1">
<result name="no">
<param name="location">/index.jsp</param>
</result>
</action>
<action name="xiugai" class="com.wiew.UserView" method="execute2">
<result name="no">
<param name="location">/index.jsp</param>
</result>
</action>
execute1方法和execute2方法分别实现添加和更新功能!
------解决方案--------------------JScript code
var formAction = document.forms['form2'].action;
document.forms['form2'].action = ....;
------解决方案--------------------