本文實例講述了JSP針對表單重復提交的處理方法。分享給大家供大家參考,具體如下:
1. 在生成表單時執行如下:
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; }}
希望本文所述對大家JSP程序設計有所幫助。
新聞熱點
疑難解答