Double Submission Solution 重复提交表单问题方案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

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)2ndsubmissionGeneratenewsessionTokenLogicsWhensubmittingthejspform,aformtokenwillbegenerated.Thefilterandtheservletaccessthevalueoftheformtokenfromthehiddenfield.1stsubmission:ThefirstrequestissendtothedoFilter()method.Ifthesessionisnull,savetheformtokenvalueintothesessionassessiontoken.Ifthesessiontoken==formtokenthenitisfirstsubmission.Afterfiltering,thedoGet()methodisinvoked.InthedoGet()method,assignanewvaluetosessiontoken.2ndsubmission:Thesecondrequestcomesin,comparetheformtokentothenewsessiontoken,theyarenotequalthenerrorpageisredirected.AnyQuestion?

1 / 14
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功