In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "what are the ways to prevent duplicate submissions". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the ways to prevent repeated submissions.
1 javascript, set a variable to allow submission only once
Var checkSubmitFlg = false; function checkSubmit () {if (checkSubmitFlg = = true) {return false;} checkSubmitFlg = true; return true;} _ document.ondblclick = function docondblclick () {window.event.returnValue = false } _ document.onclick = function doconclick () {if (checkSubmitFlg) {window.event.returnValue = false;}}
2 or javascript, set the submit button or image to disable
3 using the synchronous token mechanism of struts
Synchronous token (Token) mechanism is used to solve the problem of repeated submission in Web applications, and Struts also gives a reference implementation. Basic principles:
Before processing the incoming request, the server compares the token value contained in the request with the token value saved in the current user session to see if it matches. After the request is processed, and before the reply is sent to the client, a new token is generated that, in addition to passing to the client, replaces the old token saved in the user's session. In this way, if the user goes back to the previous submission page and submits it again, the token passed by the client is inconsistent with the token on the server side, thus effectively preventing the occurrence of repeated submission.
If (isTokenValid (request, true)) {/ / your code here return mapping.findForward ("success");} else {saveToken (request); return mapping.findForward ("submitagain");} Struts generates a unique (for each session) token based on the user session ID and the current system time, which can be implemented by referring to the generateToken () method in the TokenProcessor class. 1. Verifying the transaction control token automatically generates an implied input representative token based on the identity in the session, preventing it from being submitted twice. In action: if (! isTokenValid (request)) errors.add (ActionErrors.GLOBAL_ERROR, new ActionError ("error.transaction.token")); resetToken (request); / / delete tokens in session 3. Action has such a method to generate tokens protected String generateToken (HttpServletRequest request) {HttpSession session = request.getSession () Try {byte id [] = session.getId (). GetBytes (); byte now [] = new Long (System.currentTimeMillis ()). ToString (). GetBytes (); MessageDigest md = MessageDigest.getInstance ("MD5"); md.update (id); bmd.update (now); return (toHex (md.digest () } catch (IllegalStateException e) {return (null);} catch (NoSuchAlgorithmException e) {return (null);}} so far, I believe you have a deeper understanding of "what are the methods to prevent duplicate submissions". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.