1. Javascript. Set a variable and submit it only once.
<Script language = "JavaScript"> 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 ;}}</SCRIPT> <HTML: Form Action = "myaction. do "met Hod = "Post" onsubmit = "Return checksubmit ();"> 2 or Javascript: Set the submit button or image to disable <HTML: Form Action = "myaction. do "method =" Post "onsubmit =" getelbyid ('submitinput '). disabled = true; return true; "> <HTML: Image styleid =" submitinput "src =" images/OK _ B .gif "border =" 0 "/> Errors. add (actionerrors. global_error, new actionerror ("error. transaction. token "); resettoken (request); // Delete the token in the session 3. action has such a method to generate the token 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); Md. update (now); Return (tohex (MD. digest ();} catch (illegalstateexception e) {return (null);} catch (nosuchalgorithmexception e) {return (null );}}
During the update process, the button is prevented from being repeatedly clicked. The session is used to determine whether the JSP page can be used in JSP/servlet.
<Input type = "hidden" name = "<% = com. LIMs. util. synchrotoken. token_name %> "value =" <% = com. LIMs. util. synchrotoken. gettoken (request) %> "> |
Synchrotoken. Java
PackageCom. LIMS. util;ImportOrg. Apache. Struts. util .*; ImportJavax. servlet. http .*; ImportJavax. servlet. jsp .*; ImportOrg. Apache. Struts. Action .*;/** * <P> title: synchrotoken </P> * <P> Description: </P> * <P> copyright: Copyright (c) 2004 </P> * <P> company: netstar </P> * @ Author jstar * @ Version 1.0 * Created in 2004/04/21 */Public ClassSynchrotoken {Public Final StaticJava. Lang. String token_name = "_ token ";Public Static BooleanChecktoken (httpservletrequest request ){BooleanIsequal =False; Httpsession session = request. getsession (); string formtoken = request. getparameter (token_name); string sessiontoken = (string) session. getattribute (token_name); system. out. println ("formtoken:" + formtoken + "sessiontoken:" + sessiontoken );If(Formtoken! =Null& Sessiontoken =Null) {Session. setattribute (token_name, formtoken); isequal =True;}ReturnIsequal;}/*** Insert the method's description here. * creation date: (4/19/2004 3:23:25 pm) * @ return Java. lang. string * @ Param request javax. servlet. HTTP. httpservletrequest */Public StaticString gettoken (httpservletrequest request) {string token = "" + system. currenttimemillis (); httpsession session = request. getsession ();If(Session! =Null) {Session. removeattribute (token_name );}ReturnToken; z}/*** Insert the method's description here. * creation date: (4/19/2004 3:24:10 pm) * @ return java. Lang. String */Final StaticJava. Lang. String gettoken_name (){ReturnToken_name ;}Public StaticString message (pagecontext, string key)ThrowsJspexception {ReturnRequestutils. Message (pagecontext,Null,Null, Key );}} |
4. Add a transit page