<action name="regist" class="action.UserAction" method="regist">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="token/>
<result>/userPages/login.jsp</result>
<result name="invalid.token">/error.jsp?msg=不允許重復提交!</result>
</action>
c)在error.jsp頁面里增加如下代碼:${param.msg}當然我們也可以借鑒Struts2的token機制在原生的Servlet里實現我們自己的token機制:在regist()方法里增加如下代碼:String newsessionId = request.getSession().getSessionId();String oldSessionId= Cache.getSessionId();if(newSessionId.equals(oldSessionId)){ msg = "不允許重復提交!"; request.getRequestDispatcher("/userPages/regist.jsp").forward(request, response);}Cache.setSessionId(newSessionId);//調用服務層用戶注冊邏輯...再在/userPage/regist.jsp頁面增加如下代碼:${msg}上面的Cache是自定義的一個普通的緩存類。當然上面的代碼有些細節可能有語法錯誤,但大致如此。以上可以做到完全禁止用戶重復提交,其實有了后臺Struts2的token機制,前臺頁面不用做任何操作,但為了減輕服務器的壓力,還是應該先在頁面予以禁止。參考文檔:判斷當前瀏覽器類型:http://blog.csdn.net/xianzi0828/article/details/7582408禁止頁面重復提交:http://waj952737.iteye.com/blog/972903Struts2的token機制:http://blog.csdn.net/yutian888/article/details/6376858頂0踩新聞熱點
疑難解答