Struts resolves duplicate submission issues
Last Update:2017-02-28
Source: Internet
Author: User
Solve | problem | repeat | Repeat insert.jsp code as follows: <%@ page contenttype= "Text/html;charset=utf-8" language= "java"%><%@ taglib URI = "/web-inf/struts-bean.tld" prefix= "Bean"%><%@ taglib uri= "/web-inf/struts-html.tld" prefix= "html"%><% @ taglib uri= "/web-inf/struts-logic.tld" prefix= "logic"%><html:html locale= "true" > <head> <html:base/> <title>insert.jsp</title> </ head> <body> <html:form action= "Insert" method= "POST" > <bean: Message key= "Label.name"/><html:text property= "name"/> <bean:message key= "Label.phone"/ ><html:text property= "Phone"/> <bean:message key= "Label.address"/><html:text property= "Address"/> <html:submit ><bean:message key= "Modify.add"/></html: submit> <html:reset><bean:message key= "Button.reset"/></html:reset> </html:form><html:errors/> </body></html:html> The Prepareinsertaction code is as follows: public class Prepareinsertaction extends Action { public Actionforward Execute ( actionmapping mapping, Actionform form, HttpServletRequest request, httpservletresponse Response) { System.out.print ("Hello prepareinsertaction"); //Create a new token Savetoken (request); return Mapping.findforward ("Inserttoken"); }}insertaction code as follows: public class Insertaction extends Action { public Actionforward Execute ( Actionmapping Mapping, Actionform form, HttpServletRequest request, httpservletresponse response) throws Exception { modifyform modifyform = (modifyform) form; //Get token String token_request = Request.getparameter ("Org.apache.struts.taglib.html.TOKEN"); // Let's see what it is. System.out.println ("token in Request is:" + token_request); actionerrors errors = new Actionerrors (); //To determine if token is valid, if there is a duplicate submission for false proof, declare an error message and feedback it out if (!istokenvalid (request)) { errors.add ("Insettoken", New Actionerror ("Error.invalid.token")); saveerrors (Request, errors); Savetoken (Request); Return (new Actionforward (mapping.getinput)); } //Return!istokenvalid () to true else{ when user first commits () Resettoken (Request); } int result=new Listbean (). Add (modifyform); if (result==1) { return Mapping.findforward ("Addlist"); }else{ return Mapping.findforward ("error"); } } }modifyform code is as follows: public class Modifyform extends actionform { public void Reset (actionmapping mapping, httpservletrequest request) {this.address=null;this.name=null;this.phone=null; } public String getphone () { return phone; } public void Setphone (String phone) { This.phone = phone; } public String getaddress () { & nbsp; return address; } public void setaddress (String address) { this.address = address; } Public String getName () { return name; } public void SetName (String name) { this. Name = name; } public String getId () { return id; } public void setId (String id) { This.id = id; }}struts-config.xml configuration is as follows: <struts-config> <data-sources/> <form-beans > <form-bean name= "Modifyform" type= "Com.lyx.struts.form.ModifyForm"/ > </form-beans> <global-exceptions/> <global-forwards> <forward name= "Inserttoken" path= "/tokeninsert.jsp"/> </ Global-forwards> <action-mappings > <!--to insert a record token check the first hop action--> <action path= "/prepareinsert" type= "com.lyx.struts.action.PrepareInsertAction"/><!-- The second action--><action attribute= "Modifyform" after the token test is inserted at the record &NBSP;&NBSP;&Nbsp; input= "/tokeninsert.jsp" name= "Modifyform" path= "/insert" scope= "request" type= Com.lyx.struts.action.InsertAction "/> </action-mappings> <message-resources Parameter= "Com.lyx.struts.ApplicationResources"/></struts-config> The applicationresources.properties configuration is as follows: error.invalid.token=repeatsubmitlabel.user=usernamelable.phone= phonelabel.address=addressmodify.add=addlabel.tokeninsert=tokeninsertbutton.reset=reset