javascript asp教程服务器对象
overview:
the server object has seven (7) methods, one (1) property, zero (0) events, and zero (0) collections.
list of methods:
createobject( ) | server.createobject("adodb.recordset") create an instance of an object |
execute( ) | server.execute("filename.asp") executes an outside file (effect is similar to ssi) |
getlasterror( ) | server.getlasterror() returns location and description of the last asp error |
htmlencode( ) | server.htmlencode("some string") encodes string to html characters |
mappath( ) | server.mappath("\\virtualfolder") converts virtual path to physical path |
transfer( ) | server.transfer("filename.asp") transfers execution out of one page and into another |
urlencode( ) | server.urlencode("some string") encodes string to url standards |
below is the script for lesson 14.
<%@language="javascript"%> <html> <body> <%=server.urlencode("hello, this string is url encoded!")%> <br><br> now let's see a reprint of script14a.asp. i did not type it manually. instead, i let server.createobject( ) do all the work.<br> <strong> <% server.scripttimeout=10 var aspscriptobject = server.createobject("scripting.filesystemobject"); var mypath=server.mappath("\\") + "\\section04\\script14a.asp" var aspscript = aspscriptobject.opentextfile(mypath); var outputscript=""; while(!aspscript.atendofstream) { outputscript += aspscript.readline() + "\r"; } outputscript = new string(outputscript); outputscript=server.htmlencode(outputscript) aspscript.close(); outputscript = "<pre>" + outputscript + "</pre>"; response.write(outputscript) %> </strong> </body> </html>
click here to run the script in a new window.
i demonstrated four methods in the script14.asp. we'll take them from top to bottom.
explaining the script:
server.urlencode() does exactly what you think it does. it takes a string and encodes it to rfc 1738 standards. that's more than you ever wanted to know about server.urlencode(), isn't it?
next we have server.createobject(). in this case i created an instance of the filesystem object. the most common objects that you will instanciate are adodb.recordset, scripting.filesystemobject, scripting.dictionary, mswc.adrotator, mswc.browsertype, mswc.nextlink, and mswc.contentrotator. there are many good resources on all of these created objects. most of them are beyond the scope of this web site.
next on the list is server.mappath(). looking back at script14.asp, do you see the double slashes (\\) in the mappath argument? that's not an accident. we have to use escape characters in javascript.
the last method i demonstrate is server.htmlencode(). it converts html flags into non-html equivalents.
the lone property:
server has one property: scripttimeout. it sets the maximum number of seconds allowable for script execution. if the script execution exceeds that time, then it times out. the user gets an ugly message but at least the web server can quit executing your darned greedy script and go about other business.
下一篇: 一个可以自动创建多级目录的函数
推荐阅读
-
javascript asp教程第五课--合二为一
-
javascript asp教程第二课--转义字符
-
javascript asp教程第九课--cookies
-
javascript asp教程第四课 同时使用vbscript和javascript
-
javascript asp教程第三课 new String() 构造器
-
javascript asp教程第六课-- response方法
-
javascript asp教程第七课--response属性
-
javascript asp教程服务器对象
-
javascript asp教程第十课--global asa
-
javascript asp教程第十三课--include文件