在Web開發中我們有時需要避免表單重複提交情況,比如發生在頁面重新整理等,如果不能很好解決,可能產生大問題,如網購訂單提交。
表單 index.jsp
<%@ page language="java" import="java.util.*"
pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN">
<html>
<head>
<title>index.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<form action="mid.jsp" method="post">
使用者名稱:<input type="text" name="name"/>
密碼:<input type="password" name="password"/>
<input type="submit" value="login"/>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%response.sendRedirect("success.jsp");%>
表單提交成功,跳轉頁面success.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<title>success.jsp</title>
<h1>Sucesss!!</h1><br>
至於這麼麻煩嗎???呼叫共通提交處理函式,函式前顯示個div蓋住頁面,就OK了啊,比如轉圈圈的圖片啊,進度條啊,等等。
在Web開發中我們有時需要避免表單重複提交情況,比如發生在頁面重新整理等,如果不能很好解決,可能產生大問題,如網購訂單提交。
表單 index.jsp
<%@ page language="java" import="java.util.*"
pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN">
<html>
<head>
<title>index.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<form action="mid.jsp" method="post">
使用者名稱:<input type="text" name="name"/>
密碼:<input type="password" name="password"/>
<input type="submit" value="login"/>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%response.sendRedirect("success.jsp");%>
表單提交成功,跳轉頁面success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>success.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<h1>Sucesss!!</h1><br>
</body>
</html>