设置 value的值。在一个隐藏域value设置不同的值。在后台根据value不同的值操作不同的方法
<div class="providerAdd">
<form id="userForm" name="userForm" method="post" action="${pageContext.request.contextPath }/jsp/user.do">
<input type="hidden" name="method" value="savepwd">
<!--div的class 为error是验证错误,ok是验证成功-->
<div class="info">${message}</div>
<div class="">
<label for="oldPassword">旧密码:</label>
<input type="password" name="oldpassword" id="oldpassword" value="">
<font color="red"></font>
</div>
<div>
<label for="newPassword">新密码:</label>
<input type="password" name="newpassword" id="newpassword" value="">
<font color="red"></font>
</div>
<div>
<label for="rnewpassword">确认新密码:</label>
<input type="password" name="rnewpassword" id="rnewpassword" value="">
<font color="red"></font>
</div>
<div class="providerAddBtn">
<!--<a href="#">保存</a>-->
<input type="button" name="save" id="save" value="保存" class="input-button">
</div>
</form>
</div>
下面通过对name = “method” 的值等于”savepwd“ 来继续判断,通过判断两个值是否相等来到达,使用不同的后端方法(个人理解:这是因为type=“hidden” 是一个隐藏的文本,在前端是看不见的,是随着form表单的提交一同交给后端处理的,若表单提交成功,则后端会收到该值,故可以根据它来判断,前端是否传递了表单。)
String method = req.getParameter("method");
if("savepwd".equals(method)){
updatePwd(req,resp);
}
}