<HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <% <br/> If request. form ("subfrm") = "btnrun" then <br/> 'the output cookie is cookiename = user = cookieuservalue & IP = cookieipvalue; Path =/ABC; domain = 192.168.18.25 <br/> response. cookies ("cookiename") ("ip") = "cookieipvalue" <br/> response. cookies ("cookiename") ("user") = "cookieuservalue" <br/> end if <br/> If request. form ("subfrm") = "btnget" then <br/> 'to the body Output <br/> response. write (request. cookies ("cookiename") ("ip ")) <br/> end if <br/> %> <br/> </pead> <br/> <title> No title page </title> <br/> <MCE: script Language = "JavaScript"> <! -- </P> <p> function getcookie (name) <br/>{< br/> M = document. cookie; <br/> RE1 = new Regexp ("(?! \ W) "+ name +" = [^;] + "," "); <br/> re2 = new Regexp (" ^ "+ name +" = ", ""); <br/> try <br/> {<br/> var A = m. match (RE1) [0]; <br/>}< br/> catch (e) <br/>{< br/> return NULL; <br/>}< br/> eval ("Var o =" +. replace (re2 ,"{"). replace (// G ,"',"). replace (/=/g, ": \ '") + "'}"); <br/> return O; <br/>}< br/> function readcookie () {alert (getcookie ("cookiename "). IP) ;}< br/> 'output cookie is cookiename = IP = cookievalue; Path =/ABC/; domain = 192.168.18.25 <br/> function writecookie () {document. cookie = "cookiename" + "= IP =" + "cookievalue" ;}< br/> function clearcookie () {document. cookie = "" ;}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <Table border = "0" cellpadding = "0" cellspacing = "0" width = "778px"> <br/> <tr> <br/> <TD style = "height: 100px; width: 778px; "align =" center "valign =" Middle "> cookie example (operations on IP addresses) </TD> <br/> </tr> <br/> <TD align = "center" style = "height: 25px; width: 778px; "> <br/> <form action =" default. ASP "method =" Post "> <br/> <input name =" subfrm "type =" Submit "id =" btnrun "value =" btnrun "/> <br/> <input name = "subfrm" type = "Submit" id = "btnget" value = "btnget"/> <br/> <input name = "subfrm" type = "Submit" id = "btnclr" value = "btnclr"/> <br/> </form> <br/> <button type = "button" onclick = "writecookie () "> set cookie on the client </button> <br/> <button type =" button "onclick =" readcookie () "> client-side cookie reading </button> <br/> <button type =" button "onclick =" clearcookie () "> clear cookie on the client </button> <br/> </TD> <br/> </tr> <br/> </table> <br/> </form> <br/> </body> <br/> </ptml> <br/>
The two methods are different.
Because JavaScript uses String concatenation to operate cookies, it is not convenient. Therefore, when using js to operate cookies, you can use less two-dimensional cookies. In ASP, because two-dimensional cookies can encapsulate multiple attributes, therefore, it also brings convenience.
Different output paths
AsP
The output path contains a slash less than the JS output path. In some cases, the actual upload may be slightly different:
If the applicationProgramIf you specify a path that does not contain a slash (/), the browser will not interpret it as a directory. Instead, it submits the cookie to any path that matches the specified pattern. For example, if the application specifies/apps as the path range, in addition to the path/apps, the browser also submits its cookies to the path/apps-test/,/apps-old/, and all their subdirectories. This behavior may not be desired by developers.