2013-04-08 185 views
-1

我需要编写一个简单的网页,可以通过参数的POST是更新得到最后的检索放慢参数值:如何通过参数,将其发送POST请求更新网页,并通过发送GET请求,它

  1. 使用参数向页面发送POST请求 - 将不断更新网页。
  2. 发送GET请求的页面将返回参数

例如最后获取的值(也许每个请求是不同的会话):

POST /mypage.asp?param1=Hello 

GET /mypage.asp >> Response: Hello 

POST /mypage.asp?param1=Changed 

GET /mypage.asp >> Response: Changed 

回答

0
<% 
dim fileSystemObject,Text_File,Text_File_Content,NewValue 

NewValue=Request.QueryString("MyParam") 
set fileSystemObject=Server.CreateObject("Scripting.FileSystemObject") 

If NewValue <> "" Then 
    set Text_File=fileSystemObject.CreateTextFile("C:\MyPath\myTextFile.txt") 
    Text_File.write(NewValue) 
    Text_File.close 
End If 

if fileSystemObject.FileExists("C:\MyPath\myTextFile.txt")=true then 
    set Text_File=fileSystemObject.OpenTextFile("C:\MyPath\myTextFile.txt",1,false) 
    Text_File_Content=Text_File.ReadAll 
    Text_File.close 
else 
    set Text_File=fileSystemObject.CreateTextFile("C:\MyPath\myTextFile.txt") 
    Text_File.write("Please send GET request to this page with paramter MyParam!") 
    Text_File.close 
    set Text_File=fileSystemObject.OpenTextFile("C:\MyPath\myTextFile.txt",1,false) 
    Text_File_Content=Text_File.ReadAll 
    Text_File.close 
end if 

Response.Write(Text_File_Content) 
%> 
0

使用$ _SESSION

session_start(); 

if($_SERVER['REQUEST_METHOD'] == "POST") 
    $_SESSION['last_val'] = $_POST['some_val']; 
} 

if($_SERVER['REQUEST_METHOD'] == "GET") 
    echo $_SESSION['last_val']; 
} 

Learn more about SESSION

+0

我需要的网页返回之后的参数的值时,我会在你的OP – SharonBL 2013-04-08 16:10:19

+0

你说'POST'到该页面 - 更新它。 GET - 检索上次POST的参数 – 2013-04-08 16:10:43

+0

POST发送GET请求,它 – SharonBL 2013-04-08 16:11:46

0

Evan的回答是在概念上是正确的,但我认为他没有解决不同的会话,也没有使用“经典ASP”(vbscript或jscript)。

要在会话和请求之间保持一个值,您需要某种形式的存储。可能最简单的选项是一个应用程序变量(我在下面显示)。其他选项是“线程安全”存储,如广泛使用的CAPROCK DICTIONARY或数据库。

代码:

<%@ Language="VBScript" %> 
<% 
If Request.ServerVariables("REQUEST_METHOD")= "POST" Then 
Application.Lock 
Application("StoredValue") = Request.Form("param1") 
Application.Unlock 
Else 
Application.Lock 
Response.Write Application("StoredValue") 
Application.Unlock 
End If 
%>