- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章javascript asp教程第九课--cookies由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
Response Cookies in General
We'll start with the Response Cookies collection. I don't think it could be any easier. You simply put the name of the cookie in the argument. The corresponding value is a string. The only time it gets complicated is when you use keys (which I demonstrate below). 。
<%@LANGUAGE="JavaScript"%><%var Tomorrow=new Date()Tomorrow.setDate(Tomorrow.getDate() + 1)myExpire = (Tomorrow.getMonth() + 1) + "/" + Tomorrow.getDate() myExpire += "/" + Tomorrow.getFullYear()Response.Cookies("firstCookie") = "I like cookies."Response.Cookies("firstCookie").Expires=myExpireResponse.Cookies("secondCookie") = "ASP Cookies Are Easy."Response.Cookies("secondCookie").Expires=myExpireResponse.Cookies("thirdCookie")("firstKey")="Here's the first Key."Response.Cookies("thirdCookie")("secondKey")="Here's the second Key."Response.Cookies("thirdCookie").Expires=myExpire%><HTML>We're just setting <%=Response.Cookies.Count%> cookies.<BR><A HREF="script09a.asp">Click Here</A> to retrieve these cookies.</HTML>
Click Here to run the script in a new window. 。
Setting a cookie with ASP is pretty simple. The format is Response.Cookies("name")="value" . That "value" can be either a JavaScript string or an ASP native type such as Request.Form("userEmail"). 。
Response Cookie Keys
If on the first page of your ASP application Response.Cookies("myOnlyCookie") is set, and subsequently on page two of your application Response.Cookies("myOnlyCookie") is reassigned a second value, then only the second value will remain. The first value is lost in this circumstance. 。
The solution is to either use multiple cookies or to use multiple Keys in the SAME cookie. 。
Response.Cookies("thirdCookie")("firstKey")="Here's the first Key."Response.Cookies("thirdCookie")("secondKey")="Here's the second Key."
The Setting of one or more Keys is pretty simple. It follows this format: Response.Cookies("name")("key")="value" . Again, the "value" can either be a JavaScript string or ASP native type. The advantage of using keys is that you can store multiple Key/Value pairs inside the very same cookie. 。
Request Cookies
Generally you will find ASP cookie management to be far easier than Client Side JavaScript cookies. Down below is the script that retrieves the cookies. 。
<%@LANGUAGE="JavaScript"%><%if (Response.Cookies.Count <= 0) { Response.Redirect("script09.asp") }var firstCookie = Request.Cookies("firstCookie"); var secondCookie = Request.Cookies("secondCookie");var thirdCookie2Keys = Request.Cookies("thirdCookie")("firstKey") thirdCookie2Keys += " " + Request.Cookies("thirdCookie")("secondKey");%><HTML>There are <%=Request.Cookies.Count%> Cookies.<BR>1) <%=firstCookie%><BR>2) <%=secondCookie%><BR>3) <%=thirdCookie2Keys%><BR><A HREF="script09b.asp">Click Here</A> to see how we would sort cookiesif we didn't know their names.</HTML>
Click Here to run the script in a new window. 。
Do I even need to explain "firstCookie" and "secondCookie"? It's so easy. However, I will have to have explain the retrieval of Keys in "thirdCookie". 。
We retrieve cookies in almost exactly the same way that we set them, and that goes for Keys as well. If you keep track of your Key names, then retrieving their values is pretty easy. 。
var thirdCookieFirstKey = Request.Cookies("thirdCookie")("firstKey")
Deleting Cookies
To delete a cookie, give it an expiration date in the past. The following is not in our examples, but it would work. 。
var Yesterday=new Date()Yesterday.setDate(Yesterday.getDate() - 1)myExpire = (Yesterday.getMonth() + 1) + "/" + Yesterday.getDate() myExpire += "/" + Yesterday.getFullYear()Response.Cookies("firstCookie").Expires=myExpire
Cookie Crumbs
What if you lose track of your cookie names? What if you lose your Keys? First of all, don't do that. But secondly, we have options. 。
We can use a VBScript Function with a for/each loop. We can use Javascript's new Enumerator( ) or we can use a pair of for Loops. We, however, cannot use JavaScript's for/in loop. This means we have to be creative. 。
<%@LANGUAGE="JavaScript"%><%if (Response.Cookies.Count <= 0) { Response.Redirect("script09.asp") }%><HTML><SCRIPT LANGUAGE="VBScript" RUNAT="Server">Function forEachCookie()dim x,y,zfor each x in Request.Cookies if Request.Cookies(x).HasKeys then for each y in Request.Cookies(x) z = z & x & ":" & y & "=" & Request.Cookies(x)(y) & "; " next else z = z & x & "=" & Request.Cookies(x) & "; " end ifnextforEachCookie = zEnd Function</SCRIPT><%Response.Write("<STRONG>Let's use a VBScript function to ")Response.Write("sort out the Cookies and Keys.</STRONG><BR>\r")var longCookie = forEachCookie()if (longCookie) { longCookie = longCookie.split("; ") for (i=0;i<=longCookie.length-1;i++) { Response.Write(longCookie[ i ] + "<BR>\r") } }Response.Write("<HR>\r")Response.Write("<STRONG>Let's use <I>new Enumerator( )</I> to ")Response.Write("sort out the Cookies and Keys.</STRONG><BR>\r")var myEnum = new Enumerator(Request.Cookies);for (myEnum; !myEnum.atEnd() ; myEnum.moveNext() ) { Response.Write(myEnum.item() + "=") n=Request.Cookies(myEnum.item()).Count if (n) { for (o=1;o<=n;o++) { Response.Write(Request.Cookies(myEnum.item())(o) + " ") } //Begin alternate method of using Enumerator() Response.Write("<BR>\r<STRONG>OR... </STRONG>") Response.Write(myEnum.item() + "=") Response.Write(unescape(Request.Cookies(myEnum.item()))) //End alternate method } else { Response.Write(Request.Cookies(myEnum.item())) } Response.Write("<BR>\r") }Response.Write("<HR>\r")Response.Write("<STRONG>Let's use a pair of JavaScript loops to ")Response.Write("sort out the Cookies and Keys.</STRONG><BR>\r")a=Request.Cookies.Countfor (b=1;b<=a;b++) { d = Request.Cookies(b).Count if (d) { for (c=1;c<=d;c++) { Response.Write(Request.Cookies(b)(c) + " ") } Response.Write("<BR>\r") } else { Response.Write(Request.Cookies(b) + "<BR>\r") } }%> </HTML>
Click Here to run the script in a new window. 。
We do the same job three times. You decide for yourself which one you like best. In the first example you can plainly see from the script, I ask a VBScript function to find and break down all the cookies. I then output the data back to the waiting JavaScript variable. 。
var longCookie = forEachCookie()
What can I say? Don't lose track of your cookies and don't lose track of your Keys. Otherwise you might have to get a VBScript slim jim. 。
The new Enumerator() is okay. I use Enumerator two different ways; one way fails to capture the Key names, and the other way successfully captures the key names (but it needs unescape() to get the Key values to print normally). 。
In round three, I use a pair of for loops, but they're not as functional as for/in would be. (Notice the lack of Key names.) 。
Misc. Notes
We didn't use new String( ) in this lesson. But remember, if you want to manipulate the cookie values inside JavaScript functions or methods, then you will need new String(). 。
var firstCookie = new String(Request.Cookies("firstCookie") )firstCookie = firstCookie.toUpperCase()
Also, if you were to use Client Side scripting to locate cookies, you would have noticed that there is an extra cookie. ASP keeps track of its sessions using a cookie. 。
最后此篇关于javascript asp教程第九课--cookies的文章就讲到这里了,如果你想了解更多关于javascript asp教程第九课--cookies的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在为数据结构类(class)做期末练习,我有几个问题希望得到帮助: void BST::traverse(Vertex *V) // post order traversal recursive
我正在 udacity.com 上进行 Android 开发培训,随后进行了 sunny 应用程序的实现。我正在使用 android studio 最新版本进行实现。 我正要到达我应该获得模拟 Lis
~~~更新:已解决!谢谢大家!~~~ 我正在研究 Blue Pelican Java 书中的一个项目,第 16 课项目 Gas Mileage。它要求创建两个类,一个是 Automobile,它包含我
我已经阅读了很多有关依赖注入(inject)、控制反转和 IoC 容器的文章。我还主要使用动态语言编程(工作中使用 PHP,在家使用 Python)。以下是我找到的东西,但是当我将它们拼凑在一起时,这
我有以下类层次结构: interface Repository // This class contains some common stuff for LocalRepository and Rem
我正在观看 Erik Meijer 的 Functional Programming Fundamentals 系列讲座(附有 Graham Hutton 的幻灯片)。 在 lecture 8 (on
一个文本文件包含有关垒球队的信息。每行数据排列如下: 4 Jessie Joybat 5 2 1 1 第一项是玩家的编号,方便地在 0-18 范围内。第二项是玩家的名字,第三项是玩家的姓氏。每个名字都
我正在学习 Codility 计数课 ( https://codility.com/media/train/2-CountingElements.pdf ),我需要帮助来了解最快的解决方案。 我想知道
我是编码新手,即将完成“使用 Swift 进行 App 开发入门”iBook。我目前正在学习第 19 课,枚举和开关,在相关 Playground 的第 8 页,它显示了以下代码: enum Lunc
我真的尝试过研究这个问题,但我现在离它太近了,我担心如果不寻求帮助我就找不到解决方案。我正在学习 RubyMonk,其中一个练习让我完全不知所措。 class Hero def initializ
在观看 Lecture 10 iTunes 视频的同时尝试跟进并编写 Smashtag 项目。 当我将下载的 Twitter 包添加到我的 Smashtag 项目时,当我在 TweetTableVie
public int solution(int[] A) { int lengthOfArray = A.length; int tempArray[] = new int[lengt
所以我收到此错误消息,指出无法解析fragment_ main xml 中的符号它出现在这行代码上 tools:context=".MainActivity$ForecastFragment">其中的
使用 NodeSchool.io 学习 Node.js,我对以下两个代码段之间的差异感到困惑。这种差异可能对于 Node.js 或一般的 JS 来说是根本性的,所以我希望专家能够向我澄清这一点。 第
这是我想为每个行为类似于切片的类型实现的特征(针对问题进行了简化): trait SliceLike { type Item; /// Computes and returns (ow
这节课应该非常简单。他们拼出了答案,但我自己和论坛中的 10 多个人无法让本类(class)发挥作用。 我们是否错误地实现了代码?教训是否具有误导性?答案检查器是否已损坏? http://www.co
我将在 udacity.com 上接受 Android 开发人员培训,然后实现 Sunshine 应用程序。我正在使用 Android Studio,最新版本默认安装。 我正处于我应该拥有一个带有模拟
这个问题已经有答案了: Why is "None" printed after my function's output? (7 个回答) 已关闭 6 年前。 我已经在互联网上搜索并尝试了代码的变体,
我无法在我的 Rails 应用程序中使用 Ajax。 借助 Ajax 的魔力:当我单击“关注”按钮时,它应该更新用户在个人资料页面中看到的关注者数量,而无需刷新页面。但是,在我的示例应用程序中,这并没
我正在关注关于 Redux 的 egghead.io 教程。我在第 17 课上遇到了 Dan Abramov 没有的错误。代码如下。 我得到的错误是 “类型错误:无法读取未定义的属性‘map’ 根据我
我是一名优秀的程序员,十分优秀!