资源描述:
《简述session与cookie区别(简述会话cookie区别与)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、简述session与cookie区别(简述会话cookie区别与)Sessionisthestoragespaceofaservermaintainedbytheendoftheapplicationserver,userscormectingtotheserver,willgenerateauniqueSessionlDSessionstoragespacebytheserver,usingtheSessionlDidentifiertoaccessserver・TheSessionlDdataissavedtotheclientandstoredinCookie・Whentheu
2、sersubmitsthepage,itsubmitstheSessionlDtotheservertoaccesstheSessiondata・Thisprocessisnotinterventionbydevelopers・SooncetheclientdisablesCookie,thentheSessionwillfai1.TheservercanalsopassthevalueofSessionlDthroughURLoverwrite,soitisnotentirelydependentonCookie・IftheclientCookieisdisabled,theser
3、verautomaticallysavesthevalueoftheSessionbyoverridingtheURL,andtheprocessistransparenttotheprogrammer・Youcantry,ifnotwriteCookie,intheuseofrequest・getCookies(Cookie);removethearraylengthis1,andthenameofthisCookieisJSESSIONID,thereisaverylongbinarystringisthevalueofSessionlD・Cookieistheclient,ss
4、toragespace,maintainedbybrowsers・Insomesituationssuchasvoting,weoftenbecausetheprincipleoffairnessforeachpersoncanonlyvoteinsomeWEBinthedevelopmentofthesituationissimilar,weusuallyuseCOOKIEtorealize,forexamplethefollowingcode:<%cookie[]cookies=request.getCookies();If(cookies・lenght二0cookies二二nu
5、ll)DoStuffForNewbie();//notvisitedElse(doStuffForReturnVisitor);//havevisited%>Itisveryeasytounderstandthetruth,todetecttheexistenceofCOOKIE,iftherethathaverunwriteCOOKIEcode,however,runtheabovecode,wheneverresultsareexecuted(doStuffForReturnVisitor),throughthe-Internetcontrolpanelset-viewfileb
6、utalwayscannotseethegeneratedcookiefile,strange・Whenthecodeisnoproblem,butsincethereiscookie,itisshow.Cookie[]cookies二request・getCookies();If(cookies,lenght=0
7、
8、cookies二二null)Out・printin("Hasnotvisitedthiswebsite");ElseFor(inti二0;I9、"cookievalue:z/+Cookie[i]・getValue());}}Operationresult:Cookiename:JSESSIONIDcookievalue:KWJHUG6JJM65HS2K6Whyiscookie,weallknowthatHTTPisastatelessprotocol,clientreadthewebpage,theserverwillopenanewsession,buttheserverwillnotautom