当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP > ASP Quick Ref

ASP
ASP Drive
ASP File
ASP Folder
ASP Dictionary
ASP ADO
ASP AdRotator
ASP BrowserCap
ASP Content Linking
ASP Content Rotator
ASP Quick Ref
ASP 摘要
ASP 实例

ASP Quick Ref


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 505 ::
收藏到网摘: n/a

Basic Syntax
基本语法

ASP scripts are surrounded by <% and %>.  To write some output to a browser:
ASP脚本可以写在“<%和%>”之中,举例:

<html>
<body>
<% response.write("Hello World!") %>
</body>
</html>

The default language in ASP is VBScript. To use another scripting language, insert a language specification at the top of the ASP page:
ASP默认的语言是ASP和VBScript;如果你希望使用另外一种脚本语言,你必须在ASP页面的开头插入一段语句,例:

<%@ language="javascript" %>
<html>
<body>

<%
....
%>

Forms and User Input
表单和用户输入

Request.QueryString is used to collect values in a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.
Request.QueryString是用来收集用“get”方式传输的表单变量的。通过“Get”方式发送的变量信息对任何人来说都是可见的(他将显示在浏览器的地址栏里),但是,他对发送信息的长度有限制。

Request.Form is used to collect values in a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
Request.Form是用来收集用“post”方式传输的表单变量的。通过“post”方式发送的变量信息对别人来说都是不可见的,然而,它对发送信息的长度没有限制。

ASP Cookies

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests for a page with a browser, it will send the cookie too.
Cookie通常是用来确认用户身份的。Cookie是通过服务器发送到用户计算机中的一小段文件。每次,当相同的计算机通过浏览器请求页面时,他也同样会把Cookie发送过去。

The Response.Cookies command is used to create cookies:
Response.Cookies命令是用来建立Cookies的:

<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname").Expires="May 10,2002"
%>

Note: The Response.Cookies command must appear BEFORE the <html> tag!
注意:Response.Cookies命令必须写在<html>标签之前。

The "Request.Cookies" command is used to retrieve a cookie value:
Request.Cookies命令是用来获取Cookie值的:

<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>

Including Files
包含的文件

You can insert the content of one ASP file into another ASP file before the server executes it, with the #include directive. The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages
你可以使用#include在服务器执行某个ASP文件之前将这个ASP文件插入到另外一个ASP文件内。

Syntax:
语法:

<!--#include virtual="somefile.inc"-->
or
<!--#include file ="somefile.inc"-->

Use the virtual keyword to indicate a path beginning with a virtual directory. If a file named "header.inc" resides in a virtual directory named /html, the following line would insert the contents of "header.inc":
使用virtual关键词在指定一条虚拟路径。如果一个名为“header.inc”的文件保存在名为“/html”的虚拟文件夹下,那么使用下面的代码将插入“header.inc”的内容:

<!-- #include virtual ="/html/header.inc" -->

Use the file keyword to indicate a relative path. A relative path begins with the directory that contains the including file. If you have a file in the html directory, and the file "header.inc" resides in htmlheaders, the following line would insert "header.inc" in your file:
使用file关键词指出一条相对路径。相对路径始于当前文件夹,它包含了其中所有的文件。如果你在HTML文件夹中有一个文件,而“header.inc”文件又在“htmlheaders“路径下,那么,插入“header.inc”文件的方法如下:

<!-- #include file ="headersheader.inc" -->

Use the file keyword with the syntax (..) to include a file from a higher-level directory.
提示:使用file关键词时,如果使用“<..>”,则文件的路径要从最高级目录算起。

Global.asa

The Global.asa file is an optional file that can contain declarations of objects, variables, and methods that can be accessed by every page in an ASP application.
Global.asa文件是一个可选文件,它包括了对对象、变量的声明以及对每个页面应用程序访问方法的声明。

Note: The Global.asa file must be stored in the root directory of the ASP application, and each application can only have one Global.asa file.
注意:Global.asa文件必须被存储在ASP程序文件的根目录中,且每个应用程序文件只能拥有一个Global.asa文件。

The Global.asa file can contain only the following:
Global.asa文件只能包含以下内容:

  • Application events
    Application 事件
  • Session events
    Session 事件
  • <object> declarations  
    <object> 声明
  • TypeLibrary declarations
    TypeLibrary 声明
  • the #include directive
    #include 关键词

Application and Session Events
Application事件和Session事件

In Global.asa you can tell the application and session objects what to do when the application/session starts and what to do when the application/session ends. The code for this is placed in event handlers. Note: We do not use <% and %>, to insert scripts in the Global.asa file, we have to put the subroutines inside the HTML <script> tag:
在Global.asa文件当中,你可以在它们开始或结束的时候区别Application和Session这两个对象,这些代码被放置在了事件处理器当中。注意:我们不使用“<%”和“%>”向Global.asa文件中插入脚本,我们需要把子程序放置到HTML<script>标签中。

<script language="vbscript" runat="server">
sub Application_OnStart
  ' some code
end sub
sub Application_OnEnd
  ' some code
end sub
sub Session_OnStart
  ' some code
end sub
sub Session_OnEnd
  ' some code
end sub
</script>

<object> Declarations
<object>声明

It is also possible to create objects with session or application scope in Global.asa by using the <object> tag. Note: The <object> tag should be outside the <script> tag!
我们也可以通过使用Global.asa中的<object>标签建立session和application对象。注意:<object>标签必须写在<script>标签之外

Syntax:
语法:

<object runat="server" scope="scope" id="id"
{progid="progID"|classid="classID"}>
.......
</object>

TypeLibrary Declarations
Typelibrary声明

A TypeLibrary is a container for the contents of a DLL file corresponding to a COM object. By including a call to the TypeLibrary in the Global.asa file, the constants of the COM object can be accessed, and errors can be better reported by the ASP code. If your Web application relies on COM objects that have declared data types in type libraries, you can declare the type libraries in Global.asa.
TypeLibrary声明涵盖了所有与COM对象相关的DLL文件的内容。通过呼叫Global.asa文件中的TypeLibrary,可以访问COM对象常量,所有的错误可以通过ASP代码很好的被显示出来。如果你的网络应用程序依赖一些已经在type library中声明了数据类型的COM对象,你也可以在Global.asa文件中声明type libraries。

Syntax:
语法:

 <!--METADATA TYPE="TypeLib"
file="filename"
uuid="typelibraryuuid"
version="versionnumber"
lcid="localeid"
-->

The Session Object
Session对象

The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are available to all pages in one application.
Session对象是为用来存储使用者session信息或者改变使用者session设置的属性的。存储在Session对象中的变量包含了单个用户的所有信息,并且应用程序中的所有页面都是有效的。

Collections
Collections集合

  • Contents - Holds every item added to the session with script commands
    Contents –通过使用脚本命令将每一个项添加到session中
  • StaticObjects - Holds every object added to the session with the <object> tag, and a given session
    StaticObjects – 通过<object>标签和一个给定的session将每个对象添加到session中
  • Contents.Remove(item/index) - Deletes an item from the Contents collection
    Contents.Remove(item/index) – 从Contents集合中删除一个项
  • Contents.RemoveAll() - Deletes every item from the Contents collection
    Contents.RemoveAll() -从Contents集合中删除所有项

Properties
属性

  • CodePage - Sets the code page that will be used to display dynamic content
    CodePage – 设置一个用来显示动态内容的代码页
  • LCID - Sets the locale identifier that will be used to display dynamic content
    LCID – 设置用来显示动态内容的标志符
  • SessionID - Returns the session id
    SessionID – 返回session id
  • Timeout - Sets the timeout for the session
    Timeout – 设置session的过期时间 

Method
方法

  • Abandon - Kills every object in a session object 
    Abandon – 删除所有Session对象

Application Object
Application对象

A group of ASP files that work together to perform some purpose is called an application. The Application object in ASP is used to tie these files together. All users share one Application object. The Application object should hold information that will be used by many pages in the application (like database connection information).
一组为了实现某些目的和功能而在一起协同工作的ASP文件称为一个Application(应用程序)。ASP中的Application对象是用来绑定所有这些ASP文件的。所有的用户可以共享一个Application对象。通过Application对象所保存的所有信息可以在任何页面中使用(比如数据库连接信息)。

Collections
集合

  • Contents - Holds every item added to the application with script commands
    Contents – 使用脚本命令将每一项添加到application
  • StaticObjects - Holds every object added to the application with the <object> tag
    StaticObjects – 使用<object>标签将所有对象添加至application中
  • Contents.Remove - Deletes an item from a collection
    Contents.Remove – 从集合中删除其中一项
  • Contents.RemoveAll - Deletes every item from a collection
    Contents.RemoveAll -从集合中删除所有项

Methods方法

  • Lock - Prevents a user from changing the application object properties
    Lock – 加锁。防止用户改变application对象的属性
  • Unlock - Allows a user to change the application object properties
    Unlock – 解锁。允许用户改变application对象的属性

The Response Object

The Response Object is used to send output to the user from the server.

Collection

  • Cookies(name) - Sets a cookie value. If the cookie does not exist, it will be created, and take the value that is specified

Properties

  • Buffer - Whether to buffer the output or not. When the output is buffered, the server will hold back the response until all of the server scripts have been processed, or until the script calls the Flush or End method. If this property is set, it should be before the <html> tag in the ASP file
  • CacheControl - Sets whether proxy servers can cache the output or not. When set to Public, the output can be cached by a proxy server
  • Charset(charset_name) - Sets the name of the character set (like "ISO8859-1") to the content type header
  • ContentType - Sets the HTTP content type (like "text/html", "image/gif", "image/jpeg", "text/plain"). Default is "text/html"
  • Expires - Sets how long a page will be cached on a browser before it expires
  • ExpiresAbsolute - Sets a date and time when a page cached on a browser will expire
  • IsClientConnected - Checks if the client is still connected to the server
  • Pics(pics_label) - Adds a value to the pics label response header
  • Status - Specifies the value of the status line

Methods

  • AddHeader(name, value) - Adds an HTML header with a specified value
  • AppendToLog string - Adds a string to the end of the server log entry
  • BinaryWrite(data_to_write) - Writes the given information without any character-set conversion
  • Clear - Clears the buffered output. Use this method to handle errors. If Response.Buffer is not set to true, this method will cause a run-time error
  • End - Stops processing the script, and return the current result
  • Flush - Sends buffered output immediately. If Response.Buffer is not set to true, this method will cause a run-time error
  • Redirect(url) - Redirects the user to another url
  • Write(data_to_write) - Writes a text to the user

Request Object

When a browser asks for a page from a server, it is called a request. The Request Object is used to get information from the user.

Collection

  • ClientCertificate - Holds field values stored in the client certificate
  • Cookies(name) - Holds cookie values
  • Form(element_name) - Holds form (input) values. The form must use the post method
  • QueryString(variable_name) - Holds variable values in the query string
  • ServerVariables(server_variable) - Holds server variable values

Property

  • TotalBytes - Holds the total number of bytes the client is sending in the body of the request

Method

  • BinaryRead - Fetches the data that is sent to the server from the client as part of a post request

Server Object

The Server Object is used to access properties and methods on the server.

Property

  • ScriptTimeout - Sets how long a script can run before it is terminated

Method

  • CreateObject(type_of_object) - Creates an instance of an object
  • Execute(path) - Executes an ASP file from inside another ASP file. After executing the called ASP file, the control is returned to the original ASP file
  • GetLastError() - Returns an ASPError object that will describe the error that occurred
  • HTMLEncode(string) - Applies HTML encoding to a string
  • MapPath(path) - Maps a relative or virtual path to a physical path
  • Transfer(path) - Sends all of the state information to another ASP file for processing. After the transfer, procedural control is not returned to the original ASP file
  • URLEncode(string) - Applies URL encoding rules to a string

Source : http://www.w3schools.com/asp/asp_quickref.asp

评论 (0) All

登陆 | 还没注册?