加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp-classic – 如何检查VBScript中是否存在POST提交字段?

发布时间:2020-12-16 00:10:37 所属栏目:asp.Net 来源:网络整理
导读:提交表单后,如果存在特定字段,如何检查服务器端?例如: If [Exists] Request("FieldName") Then ...End If 解决方法 检查它是否为空.有几种不同的方式,但我经常使用的方法是: If Request("FieldName") "" Then 'etc.End If 我通常使用以下代码之一的某些变
提交表单后,如果存在特定字段,如何检查服务器端?例如:
If [Exists] Request("FieldName") Then
    ...
End If

解决方法

检查它是否为空.有几种不同的方式,但我经常使用的方法是:
If Request("FieldName") <> "" Then
 'etc.
End If

我通常使用以下代码之一的某些变体显式检查Form和QueryString集合,如果我可能从一个或另一个获取变量,具体取决于上下文:

Select Case True
    Case Request.Form("FieldName") <> ""
        'Run if the Form isn't empty
    Case Request.QueryString("FieldName") <> ""
        'Run if the QueryString isn't empty
    Case Else
        'Set a predefined default if they're both empty
End Select

或嵌套的If …然后:

If Request.Form("FieldName") <> "" Then
    'Run if the Form isn't empty
ElseIf Request.QueryString("FieldName") <> "" Then
    'Run if the QueryString isn't empty
Else
    'Set a predefined default if they're both empty
End If

如果我确切地知道它来自哪个集合,我将专门检查该集合.原因是我想确保它从我期望它来自的地方拉出我所期望的.当我不期待它时,我不希望有人通过在QueryString中发送内容来覆盖Form值.

从MSDN开始:

If the specified variable is not in one of the preceding five
collections,the Request object returns EMPTY.

All variables can be accessed directly by calling Request(variable)
without the collection name. In this case,the Web server searches the
collections in the following order:

  • QueryString
  • Form
  • Cookies
  • ClientCertificate
  • ServerVariables

If a variable with the same name exists in more than one collection,
the Request object returns the first instance that the object
encounters.

It is strongly recommended that when referring to members of a collection the full name be used. For example,rather than Request.(“AUTH_USER”) use Request.ServerVariables(“AUTH_USER”). This allows the server to locate the item more quickly.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读