简体   繁体   English

IsNumeric()不使用Request.QueryString

[英]IsNumeric() not working with Request.QueryString

I'm having problems trying to get IsNumeric to work properly with Request.QueryString. 我在尝试让IsNumeric与Request.QueryString一起正常工作时遇到了问题。

The server is Windows 2008 R2 / IIS7.5 服务器是Windows 2008 R2 / IIS7.5

My code could not be any simpler: 我的代码不能再简单了:

    <%@ LANGUAGE=VBScript %>
    <% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString("")) %>

My URL: http://localhost.com/default2.asp?44hjh 我的网址: http//localhost.com/default2.asp?44hjh

The output: IsNumeric: True 输出:IsNumeric:True

If I change my code to this, then I get the desired outcome: 如果我将我的代码更改为此,那么我会得到所需的结果:

    <%@ LANGUAGE=VBScript %>
    <% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString("test")) %>

My URL: http://localhost.com/default2.asp?test=44hjh 我的网址: http//localhost.com/default2.asp?test = 44hjh

The output: IsNumeric: False 输出:IsNumeric:False

Why does IsNumeric not work when I don't specify a specific querystring element? 当我没有指定特定的查询字符串元素时,为什么IsNumeric不起作用? And more importantly, how can I fix it? 更重要的是,我该如何解决?

Request.QueryString("") doesn't exist and thus returns NULL -- there isn't a parameter that is a blank. Request.QueryString("")不存在,因此返回NULL - 没有一个空白的参数。 IsNumeric of a NULL value will return True. NULL值的IsNumeric将返回True。

Instead of using Request.QueryString("") , you can either supply the parameter as you did in your 2nd example, or just use Request.QueryString by itself assuming no other parameters are being passed to your page: 您可以像在第二个示例中那样提供参数,而不是使用Request.QueryString("") ,或者只使用Request.QueryString ,假设没有其他参数传递到您的页面:

<% Response.Write "IsNumeric: " & IsNumeric(Request.QueryString) %>

That's because isnumeric of a null value returns an integer type. 那是因为null值的isnumeric返回一个整数类型。 That's why you get a TRUE in the first case. 这就是为什么你在第一种情况下获得TRUE的原因。 Whereas you are checking for a string type using the isnumeric in the second case. 而您在第二种情况下使用isnumeric检查字符串类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM