我在尝试使用Request.QueryString使IsNumeric正常工作时遇到问题。
服务器是Windows 2008 R2 / IIS7.5
我的代码不能再简单了:
<%@ LANGUAGE=VBScript %>
<% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString("")) %>
我的网址: http://localhost.com/default2.asp?44hjh
输出: IsNumeric:True
如果我将我的代码更改为此,那么我会得到所需的结果:
<%@ LANGUAGE=VBScript %>
<% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString("test")) %>
我的网址: http://localhost.com/default2.asp?test=44hjh
输出: IsNumeric:False
为什么当我没有指定特定的查询字符串元素时,IsNumeric不起作用?更重要的是,我该如何解决?
答案 0 :(得分:4)
Request.QueryString("")
不存在,因此返回NULL
- 没有参数为空。 IsNumeric
值的NULL
将返回True。
您可以像在第二个示例中那样提供参数,而不是使用Request.QueryString("")
,或者只使用Request.QueryString
,假设没有其他参数传递到您的页面:
<% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString) %>
答案 1 :(得分:0)
这是因为null值的isnumeric
返回整数类型。这就是为什么你在第一种情况下得到 TRUE 的原因。而您在第二种情况下使用isnumeric
检查字符串类型。