DoubleSubmitProblemSolutionTheUsageofFilterDoubleSubmitProblemDescriptionplaceOrder.jspServletDemo…Solution•Filterperformsfilteringtasksoneithertherequesttoaresource,orontheresponsefromaresource,orboth.voiddoFilter(ServletRequestreq,ServletResponseres,FilterChainchain){//implementthefilteringtaskhere…}voidinit(FilterConfigconfig){//dosomethingbeforethedoFilter()methoddoesthefilteringwork…}voiddestroy(){//indicatetoafilterthatitisbeingtakenoutofservice…}MainSteps•MyToken.javaGeneratearandomuniquetokenfortheformusingMD5algorithm•placeOrder.jspPutthetokendeclarationandhiddenfieldshownbelowonthejspfile%@pageimport=com.mercury.classes.MyToken%%!MyTokenmt=newMyToken();Stringtoken=mt.getMyToken();%inputtype=hiddenname=tokenvalue=%=token%/•DoubleSubmitServlet.java•DoubleSubmitPrevention.javaMainSteps•Configweb.xmlfilterfilter-nameDoubleSubmitPrevention/filter-namefilter-classcom.mercury.filters.DoubleSubmitPrevention/filter-class/filterfilter-mappingfilter-nameDoubleSubmitPrevention/filter-nameservlet-nameDoubleSubmitServlet/servlet-name/filter-mappingCodesandDemo…//Filter-sidecode•SevletsidecodeWorkflowJspRequestdoFilter()doGet()error.jspformTokenweb.xmlsessionToken==nullsessionToken=formTokensessionToken.equals(FormToken)=true1stsubmissionsessionToken=newvalue!sessionToken.equals(FormToken)2ndsubmissionGeneratenewsessionTokenLogicsWhensubmittingthejspform,aformtokenwillbegenerated.Thefilterandtheservletaccessthevalueoftheformtokenfromthehiddenfield.1stsubmission:ThefirstrequestissendtothedoFilter()method.Ifthesessionisnull,savetheformtokenvalueintothesessionassessiontoken.Ifthesessiontoken==formtokenthenitisfirstsubmission.Afterfiltering,thedoGet()methodisinvoked.InthedoGet()method,assignanewvaluetosessiontoken.2ndsubmission:Thesecondrequestcomesin,comparetheformtokentothenewsessiontoken,theyarenotequalthenerrorpageisredirected.AnyQuestion?