如何使用新的查询字符串重新加载ASP页面?

时间:2015-06-10 20:44:29

标签: vbscript asp-classic query-string

在VBScript中,每次运行此代码时都会收到错误消息。我只是想重新加载页面,如果" p"变量无法在querystring中找到。

我到底做错了什么?

Dim sURL            'URL of the document
sURL = document.URL

'Set page number equal to 1
If( InStr( sUrl, "?" ) = 0 ) Then
    sURL = sURL & "?p=1"
    window.location = sURL
    window.location.reload()
End If

3 个答案:

答案 0 :(得分:2)

你做错了什么?它几乎就像一切。你的代码看起来像乱七八糟的VBS和JavaScript。

您需要的是

<%@LANGUAGE=VBSCRIPT%>
<%
    If Request.QueryString("p") = "" Then
        Response.Redirect Request.ServerVariables("URL") & "?p=1"
    Else
        Response.Write "YES! WE HAVE IT!"
    End If
%>

答案 1 :(得分:1)

您可以使用

<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.5.0</version>
</dependency>

答案 2 :(得分:0)

为什么要这么麻烦?您只是假设默认值,因此当您处理页面并查找p QueryString值时,如果没有匹配的值,则将其设置为默认值...

Dim p
p = Request.QueryString("p")
If "" & p = "" Then p = 1

无需重新加载页面。

为了更进一步,我倾向于使用这样的函数......

'GetPostData
'   Obtains the specified data item from the previous form get or post.
'Usage:
'   thisData = GetPostData("itemName", "Alternaitve Value")
'Parameters:
'   dataItem (string) - The data item name that is required.
'   nullVal (variant) - The alternative value if the field is empty.
'Description:
'   This function will obtain the form data irrespective of type (i.e. whether it's a post or a get).
'Revision info:
'   v0.2 -      Function has been renamed to avoid confusion.
'   v0.1.2 -    Inherent bug caused empty values not to be recognised.
'   v0.1.1 -    Converted the dataItem to a string just in case.
function GetPostData(ByVal dataItem, ByVal nullVal)
    dim rV
    'Check the form object to see if it contains any data...
    if request.Form("" & dataItem) = "" then
        if request.QueryString("" & dataItem)="" then 
            rV = CStr(nullVal)
        else
            rV = request.QueryString("" & dataItem)
        end if
    else
        rV = request.Form("" & dataItem)
    end if
    'Return the value...
    GetPostData = rV
end function

...让我的代码保持整洁。如果缺少发布的数据,该函数只返回默认值。请注意,在返回默认值之前,此函数将实际检查QueryString和Form数据。