[英]getting type error when inserting parameterized query with vbscript in classic asp
[英]VBScript (Classic ASP): Trying to output Absolute Path of Current Dir to Browser, but getting Error
我正在嘗試使用Classic ASP將當前目錄的絕對路徑打印到瀏覽器屏幕上。 (相當於PHP的echo命令)。
我在以下代碼的最后一行遇到此錯誤:“ Microsoft VBScript運行時錯誤'800a01a8'所需對象:'Document'/Research/ro.asp,第17行”
我嘗試了幾種不同的方法來打印到屏幕上(如WScript.StdOut.Write),它們也返回相同的錯誤。
我懷疑我的錯誤與以下事實有關:它是一個對象,並且對象需要在屏幕上打印的其他方法。
任何人對此有何想法?
samplefile.asp =
<%
Dim szCurrentRoot: szCurrentRoot= ""
'Create the File System Ojbect
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Get the Absolute Path of the current directory
szCurrentRoot = objFSO.GetParentFolderName(Server.MapPath(Request.ServerVariables("URL")))
'Print to the screen. The following line is line 17 which causes the error
Document.Write(szCurrentRoot)
%>
經過更多研究后,我找到了問題的答案:
的Response.Write(szCurrentRoot)
這種寫入瀏覽器屏幕的方式很成功。
<%
Dim szCurrentRoot: szCurrentRoot= ""
'Create the File System Ojbect
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Get the Absolute Path of the current directory
szCurrentRoot = objFSO.GetParentFolderName(Server.MapPath(Request.ServerVariables("URL")))
'Print to the screen.
Response.Write szCurrentRoot
%>
Response.Write 是將文本數據發送回客戶端的方法。 使用<% %>
是此方法的快捷方式。
您不能從ASP打印到屏幕,只能使用Response.Write Server.EncodeHTML(szCurrentRoot)
或速記<%=Server.EncodeHTML(szCurrentRoot) %>
將響應寫回瀏覽器。在代碼塊中。
如果從命令行運行此文件,則不會隱式定義Yea Document
例如。
cscript無論.vbs
如果您要在IE中運行此腳本,則可以訪問“文檔”
試試這個
設置ie = CreateObject(“ InternetExplorer.Application”)ie.document.write(szCurrentRoot)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.