ASP Getting Started Tutorial-server object methods

Source: Internet
Author: User
Tags root directory

There are four methods for the server object: MapPath method, CreateObject method, HTMLEncode method, and UrlEncode method.

One, server object MapPath method

This method can map the specified relative or virtual path to the actual physical path. The syntax format is as follows:

Server.MapPaht(路径)

Instance one: The path is converted using the MapPath method of the server object. The code is as follows:

<style type= "Text/css
body,td,th {
font-size:14pt;
Color: #009999;
line-height:1.5;
}
Body {
Background-color: #D0DBF2;
margin-top:200px;
margin-bottom:0px;
}
</style>
<body>
<p align= "center" color= "#cc9999" ><b> The Mappaht method conversion path of the server object </b></p>
<table align= "center" BORDER=0>
<tr>
<td> The root directory of the server is: </td>
<td><% =server.mappath ("/")%></td></tr>
<tr>
<td > The upper level directory of the current directory is: </td>
<td><% =server.mappath (". /")%></td></tr>
<tr>
<td> The current directory is: </td>
<td><%=server.mappath ( "./")%></td></tr>
<tr><td> Current file is: </td>
<td><% =server.mappath (" 4-4b.asp ")%></td></tr>
</table>
</body>

CreateObject method of server object

This method is used to create an instance of a server component that has been registered on the server, containing all of the ASP's built-in components and the ActiveX components provided by one side. Components can be used only after an instance is created. This component extends the functionality of the ASP. The syntax format is as follows:

Server.CreateObject(ObjectParameter)

Where ObjectParameter is the type of ActiveX component to create. The ObjectParameter format is as follows:

[出版商名.]组件名[.版本号]

For example, the following script creates a Mswc.adrotator server component called MyObject that can automatically rotate advertisements on a Web page in days.

<% set MyObject=Server.CreateObject("MSWC.AdRotator") %>

Description

When you use CreateObject to create an ActiveX component, the keyword set must not be thrown away, or an error occurs when you use the defined object. By default, objects created using the Server.CreateObject method have page usage fields. In other words, after the current ASP page processing completes, the server automatically releases the objects. It is an error to attempt to create an instance object with the same name as an ASP-built object. The following code returns an error: <% Set Response=Server.CreateObject("Response")%>

Releases the system resources it occupies when the object that is created is no longer needed. You usually use nothing to eliminate the instance object. For example, to release an object named RST, you can use the following code:

<% Set Rst=Nothing %>
Related Article

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.