其实解决办法很简单,即在表单内设置一个唯一且隐藏的标签,用于存放标志该表单的值,servlet通过name获取标签的值,即可判断该表单是哪个表单。核心代码如下: servlet:
public class UserServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String type = req.getParameter("type");
if("updateUserInfo".equals(type)){
this.updateUserInfo(req,resp);
}
if ("updatePassword".equals(type)){
this.updatePassword(req,resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
public void updateUserInfo(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{}
public void updatePassword(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{}
}
jsp1(表单1):
<form action="#" name="userInfo" class="userInfo" id="userInfoForm" method="post">
<input type="hidden" name="type" value="updateUserInfo">
</div>
jsp2(表单2):
<form action="#" name="userpassword" class="updatePassword" id="updatePassword" method="post">
<input type="hidden" name="type" value="updatePassword">
</div>
|