JavaScript ASP Tutorial Server object _asp Basics

Source: Internet
Author: User

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 A instance of an Object
Execute () Server.Execute ("filename.asp")
Executes an outside file (effect are 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
a reprint of script14a.asp.
I did not type it manually. Instead, I let
Server.CreateObject () doing 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 are the it does. It takes a string and encodes it to RFC 1738 standards. That's more than your 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'll instanciate are ADODB. Recordset, Scripting.FileSystemObject, Scripting.Dictionary, MSWC. AdRotator, MSWC. BrowserType, MSWC. Nextlink, and MSWC. ContentRotator. There are many good resources to 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, does you have a double slashes (\) in the MapPath argument? That's not a 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 Business.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.