简体   繁体   中英

VBScript (Classic ASP): Trying to output Absolute Path of Current Dir to Browser, but getting Error

I'm trying to print to the browser screen the Absolute Path of the current directory using Classic ASP. (equivalent to PHP's echo command).

I'm getting this error on the last line of the code below: "Microsoft VBScript runtime error '800a01a8' Object required: 'Document' /Research/ro.asp, line 17"

I've tried a couple different methods to print to the screen (Like WScript.StdOut.Write) and they return the same error as well.

I suspect that my error has something to do with the fact that it is an object, and objects require a different method of printing to the screen.

Any thoughts on this from anyone?

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)
%>

After some more research, I found the answer to my question:

Response.Write(szCurrentRoot)

This way of writing to the browser screen was successful.

<%

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 is the way to send text data back to the client. Use <% %> is a shortcut to this method.

您不能从ASP打印到屏幕,只能使用Response.Write Server.EncodeHTML(szCurrentRoot)或速记<%=Server.EncodeHTML(szCurrentRoot) %>将响应写回浏览器。在代码块中。

Yea Document is not implicitly defined if you are running this from the command line

eg.

cscript whatever.vbs

If you were to run this script inside of IE in a you would have access to "document"

Try doing this

Set ie = CreateObject(“InternetExplorer.Application”) ie.document.write(szCurrentRoot)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM