javascript asp教程服务器对象

Overview:

The Server Object has seven (7) Methods, one (1) Property, zero (0) Events, and zero (0) Collections.

List of Methods:

Server 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.

时间: 2024-11-10 09:55:51

javascript asp教程服务器对象的相关文章

javascript asp教程服务器对象_ASP基础

Overview: The Server Object has seven (7) Methods, one (1) Property, zero (0) Events, and zero (0) Collections. List of Methods: Server Methods CreateObject( ) Server.CreateObject("ADODB.Recordset")Create an instance of an ObjectExecute( ) Serve

javascript asp教程错误处理_ASP基础

The ASPError Object has zero (0) Methods, nine (9) Properties, zero (0) Events, and zero (0) Collections. AspCode AspDescription Category Column Description File Line Number Source The way you access the ASPError Properties is with a Server Method. Y

javascript asp教程添加和修改_ASP基础

The Connection Execute(): If you want to retrieve data from a database then you have no choice but to use a Recordset. However, for the purposes of adding, updating, and deleting data you don't necessarily have to have a Recordset. It's up to you. Fo

javascript asp教程 日期相关_ASP基础

JavaScript is loosely typed. Database files are not. If you put text into a Boolean database column or a Boolean value into a date/time column, then you will get an error. For the most part this is not a problem, except for date/time. It does not cor

javascript asp教程More About Recordsets_ASP基础

Below we will attempt to access data from a database without knowing the column names. Clearly the best way to utilize data in your database is to keep track of your schema. Schema is the layout of data in your database. The concept is well beyond th

javascript asp教程Recordset记录_ASP基础

Recordset is another created/instanciated Object. It is a collection of data taken from a database. Recordset has 26 properties, 25 methods, 11 events, and two (2) collections. The vast majority of Recordset is beyond the scope of this web site. Quic

javascript asp教程创建数据库连接_ASP基础

While this section is devoted to ASP database utilization, it very important to remember that this web site is not intended to be a thorough ASP resource. Remember, the focus of this site is strictly limited to how to use JavaScript as your primary s

javascript asp教程第十一课--Application 对象_ASP基础

Overview: The Application Object represents a collection of ASP pages. The Application object has zero (0) properties, two (2) collections, two (2) methods, and two (2) events. Get Started: Below are a couple scripts for lesson11. <%@LANGUAGE="Jav

javascript asp教程第八课--request对象_ASP基础

Request Object: Request has five (5) Collections, one (1) Property, and one (1) Method. You'll use the Collections far more than the property or the method. Request Collections: Below is a table of the Request Collections and descriptions of how they