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.
上一篇: 微博营销的四大品牌价值