Struts resolves duplicate submission issues

Source: Internet
Author: User
Tags config insert key reset tld
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;   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 








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.