最近学习尚硅谷JavaWeb2020年版的教程,添加图书出现重复提交问题,经测试排查不仅添加重复提交,相应的page、delete、update都执行了两次。
测试代码如下:
控制台输出:
servlet代码
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("doget....."); // 测试用
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
System.out.println("dopost.....");// 测试用
String action = req.getParameter("action");
try {
// 通过 action 业务鉴别字符串,获取相应的业务方法反射对象
Method method = this.getClass().getDeclaredMethod(ac