436
技術社區[雲棲]
一種表單重複提交處理方法
表單重複提交處理:
1. 在生成表單時執行如下:
session.setAttribute("forum_add", "forum_add");
2. 提交處理時作如下判斷
if (isRedo(request, "forum_add")) {
//提示重複提交,作相關處理
}
相關函數:
/**
* 判斷是否為重複提交
* 1,檢查Session中是否含有指定名字的屬性
* 2,如果Session中沒有該屬性或者屬性為空,證明已被處理過,判斷為重複提交
* 3,否則,證明是第一次處理,並將屬性從Session中刪除。
* @param key String
*/
private boolean isRedo(HttpServletRequest request, String key) {
String value = (String) request.getSession().getAttribute(key);
if (value == null) {
return true;
}
else {
request.getSession().removeAttribute(key);
return false;
}
}
最後更新:2017-04-02 03:42:36