关于重复提交
①重复点击提交按钮
java
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(value = "/Test1")
public class Test1 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("来了一次请求");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
resp.sendRedirect(req.getContextPath()+"/Success.html");
}
}
在睡眠阻塞的时候页面一直跳转不过去,在期间一直点请求,算是重复提交
代码执行结果
②请求转发到后端转发去下一个页面后刷新下一个页面(网址栏和刷新圆圈 )
③重定向到下一个页面后点击"后退",再次点击提交
3.以下情况不是重复提交
①.当请求转发到下一个页面后点击"后退",再点击提交
②重定向到后端转发去下一个页面后刷新下一个页面(网址栏和刷新圆圈 )
附录:Test1.html
javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="/test0808/Test1">Test1</a>
</body>
</html>
Success.html
javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3>成功登录</h3>
</body>
</html>