Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyApplication = MyScriptingContext.Application
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MyScriptingContext.Response
Set MyServer = MyScriptingContext.Server
Set MySession = MyScriptingContext.Session
End Sub
以后我們就能用在VB中用MyApplication 來代替ASP中的Application,同理可以代替Request,Server.....,不過我們來是要在 OnStartPage之前來申明這些變量:
Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session
使用ASP的對象
我們的變量現在就能像標準的ASP對象來使用了!比如,我們經常在ASP中用Request.form()來收集提交表單的數據.現在我們在我們的VB中實現這個功能,代碼如下:
用ASP中實現:
〈%
MyTempVariable = Request.Form("userName")
Response.Write ("you entered "& MyTempVariable & "as your user name")
%>
在VB中實現:
MyTempVariable = MyRequest.Form("userName")
MyResponse.Write ("you entered "& MyTempVariable & "as your user name")
通過使用MyResponse來代替Response,我們能夠使用所有Response的方法,當然,MyResponse這個名字可以隨便來取,你甚至可以就取Response.
另一件我們得注意
文章來源于領測軟件測試網 http://www.kjueaiud.com/