Request.QueryString() 的类型是什么以及如何检查它是否为空?

What is the type of Request.QueryString() and how to check if it's empty?

也许这是个微不足道的问题,但我不知道 Request.QueryString() 的类型是什么。当我用 typeof 检查它时 - 它说它是对象。如何检查它是哪个对象以及该对象的哪个 属性 是 URL?

中的字符串

我正在使用语言规范在服务器端进行 <%@ language="javascript"%>

如果我有这样的 URL: http://127.0.0.1/Kamil/Default.asp?name= 那么如何检查名称是否为空?它不是空的。我知道我可以将 Request.QueryString("name") 转换为字符串并检查它是否为空字符串“”,但这是正确的方法吗?

Request.Querystring(未提供名称)的结果是一个字符串。 Request.Querystring("name") 的结果取决于 "name" 是否是查询字符串的一部分,如果是,它是否有值。

因此,给定以下查询字符串:

 mypage.asp?A=1&B=

如果将它们读入变量:

x = Request.Querystring("A")
y = Request.Querystring("B")
z = Request.Querystring("C")

你会得到以下结果:x = "1"(一个字符串),y = ""(一个空字符串),和 z = Empty(一个特殊值它将根据您的使用方式静默转换为字符串或数字,即 Empty = ""Empty = 0 在某种意义上都是正确的)。

Request collection is an object that inherits IRequestDictionary 界面。
实际上,在 JScript 中,使用 item to get actual value, not the implicit one due to values of the QueryString collection (also Form and ServerVariables) are IStringList 是一种很好的做法。
你说你了解 C#,所以你会理解以下虚构的 QueryString 声明。

var QueryString = new IRequestDictionary<string, IStringList>();

还有几个示例,您应该如何在不进行字符串转换的情况下检查 JScript 中的值。

if(Request.QueryString("name").count==0){
    // parameter does not exist
}

if(Request.QueryString("name").item==undefined){
    // parameter does not exist
}

if(Request.QueryString("name").item!=undefined){
    // parameter exists and may be empty
}

if(Request.QueryString("name").item){
    // parameter exists and non-empty
}