14-4 ?送?餅乾

p氮]Cookies^O Netscape qҵoiXӪAتNOnJA Http Protocals Stateless SʡAϦbȤݦs@ǸTAϱob Http Requests AOd@Ǧ@qTCڭ̥iHϥΫȤݪ JavaScript Ūgp氮AӸ`AṴ̄Ѿ\Ѧҥѫe`C`DnOQצpH ASP ӹp氮iUسBzC

Y檺Ap氮äO ASP ̭@ӳWAO Request.Cookies Response.Cookies ⳡҺcAe̥iΨŪp氮eḀiΨӳ]wp氮eC

ڭ̥iHϥ Request.Cookies(Name) ŪΤAinDɡAҶǰep氮TCѩ Request.Cookies O@ Dictionary ܼơAҥHڭ̥iH䤺ei@@CAҦpG

Example]request/listCookie01.asp^G

WzdҪlɮצpUG

lɡ]request/listCookie01.asp^G]ǦϰUYi^
<%@Language=JScript%>
<%
today= new Date();
Response.Cookies("111") = today.toLocaleString();
Response.Cookies("222") = "bbb";
%>
<% title = "H JScript LX Request.Cookies e" %>
<!--#include file="../head.inc"-->
<hr>

<!--#include file="../listdict.inc"-->
<% listdict(Request.Cookies, "Request.Cookies"); %>

<hr>
<!--#include file="../foot.inc"-->

bWzdҤAڭ̬FnϦLXӪp氮OŪAҥHڭ̥ϥ Response.Cookies("111") = today.toLocaleString() H Response.Cookies("222") = "bbb" ӳ]wFӤp氮Aۧڭ̨ϥ listdict() ƨӦLXӦs Request.Cookies Ҧp氮ȡC] Response A|bU@C^

@Ū̷|p氮]wMCǦҲVcMAHUO@²檺ҽdҡAҵ{ǦpUG

  1. oͪơGڭ̥ϥ Request.Cookes ӦCXPp氮C
  2. oͪơGڭ̦AϥΥΤݪ JavaScript ӳ]wp氮AW٬O lastLoadTimeAOJɶC
dҦpUG

Example]request/setCookieViaJs01.asp^G

zЭɡAiH[ƶG

yܻARequest.Cookies |ǰeثep氮ܦAAUA~|gѥΤݪ JavaScript ӧsp氮AoӮɶᶶǡAЯSO`NCdҪlXpUG

lɡ]request/setCookieViaJs01.asp^G]ǦϰUYi^
<%@Language=JScript%>
<% title = "H JScript LX Request.Cookies e" %>
<!--#include file="../head.inc"-->
<hr>

<script src="cookieUtility.js"></script>
<script>
today = new Date();
todayString = today.toLocaleString();
// bΤݰơG]wp氮
setCookie("lastLoadTime", todayString);
document.write("This page's loading time = " + todayString);
</script>
]p氮wgQgJALkߨ server script ܡA client script ܡC^

<h3> Server Script ܪ]ªBeA^p氮G</h3>
<!--#include file="../listdict.inc"-->
<!--bAơGCXp氮-->
<% listdict(Request.Cookies, "Request.Cookies"); %>

<h3> Client Script ܪ]ثe^p氮G</h3>
<script>listCookie();</script>

<!--
<input type=button value="Remove all cookies and reload" onClick="delAllCookie(); history.go(0)">
-->

<hr>
<!--#include file="../foot.inc"-->

ЯSO`NAbWzdҭlXAMݰ_ӧڭ̬OϥΥΤݪ JavaScript ӳ]wp氮BA Request.Cookies ӦCXҦp氮eAb涶ǤWA| ASP ӦCX Request.Cookies eAMAǨΤݡAѥΤݪ JavaScript ӳ]wp氮C

Hint
ҦASPAObAݰserver-side scriptsAM~Τݰclient-side scriptsAoӶǤ|] server-side scriptsMclient-side scriptsbmPӦҧܡC

HUAצCXp氮s@y{AHѰѦҡG

Request.Cookies utdǰep氮TܦAAYnqA]wp氮AiHϥ Response.CookiesAo|bU@C

Hint
Request.Cookeis utdǰep氮AҥHOŪAAõLkק Request.Cookies ȡC


JScript {]pPΡGΩAݪ ASP