ASP 快速参考
内置对象、常用函数、错误码、指令的一页速查。
Key Points把最常用的对象成员、VBScript 函数、常见错误号集中在一页,写代码时随手查。
内置对象
| Object | Key members |
|---|---|
Request | QueryString、Form、Cookies、ServerVariables、TotalBytes、BinaryRead |
Response | Write、BinaryWrite、Redirect、End、Flush、Buffer、ContentType、Charset、Status、AddHeader、Cookies、CacheControl、Expires |
Session | SessionID、Timeout、CodePage、LCID、Contents、Abandon |
Application | Contents、StaticObjects、Lock、Unlock |
Server | CreateObject、MapPath、HTMLEncode、URLEncode、Execute、Transfer、ScriptTimeout、GetLastError |
常用函数
| Category | Functions |
|---|---|
| String | Len、Left、Right、Mid、InStr、InStrRev、Replace、Split、Join、Trim、LTrim、RTrim、UCase、LCase、String、Space、StrReverse |
| Math | Abs、Int、Fix、Round、Rnd、Randomize、Sqr、Exp、Log |
| Date | Now、Date、Time、Year、Month、Day、Hour、Minute、Second、Weekday、DateAdd、DateDiff、DatePart、DateSerial、FormatDateTime |
| Type | CStr、CInt、CLng、CDbl、CDate、CBool、IsNull、IsEmpty、IsNumeric、IsDate、IsArray、IsObject、TypeName、VarType |
| Array | Array、Split、Join、UBound、LBound、Filter |
| Format | FormatNumber、FormatCurrency、FormatPercent、FormatDateTime |
常用语句
ASP
<%
' 条件
If x > 0 Then
' ...
ElseIf x = 0 Then
' ...
Else
' ...
End If
' 多分支
Select Case n
Case 1 : Response.Write "一"
Case 2, 3 : Response.Write "二或三"
Case Else : Response.Write "其它"
End Select
' 循环
For i = 1 To 10 Step 2
Next
For Each item In collection
Next
Do While Not rs.EOF
rs.MoveNext
Loop
Do Until x > 10
x = x + 1
Loop
%>指令
ASP
<%@ Language="VBScript" CodePage="65001" %>
<% Option Explicit %>
<% Response.Buffer = True %>
<% Session.CodePage = 65001 %>
<% Response.Charset = "UTF-8" %>
<!-- #include virtual="/includes/funcs.asp" -->常见错误号
| Number | Meaning | Typical fix |
|---|---|---|
800a000d | 对字符串做算术 | 先 CInt / CDbl |
800a01f4 | Option Explicit 下用了未声明变量 | Dim 声明 |
800a01b6 | 调用了不存在的方法 | 查组件文档 |
800a0046 | 写文件没有权限 | 给 IUSR 加写权限 |
800a0035 | 路径错或文件不存在 | MapPath 检查 |
80004005 | 数据库连接失败 | 查连接串与驱动 |
800a0009 | 数组或集合越界 | 先判 UBound / Count |
HTTP 状态码
ASP
<%
Response.Status = "404 Not Found"
Response.Status = "403 Forbidden"
Response.Status = "500 Internal Server Error"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "https://example.com/new"
%>内置对象
| 对象 | 主要成员 |
|---|---|
| 请求 | QueryString、Form、Cookies、ServerVariables、TotalBytes、BinaryRead |
| 响应 | Write、BinaryWrite、Redirect、End、Flush、Buffer、ContentType、Charset、Status、AddHeader、Cookies、CacheControl、Expires |
| 会话 | SessionID、Timeout、CodePage、LCID、Contents、Abandon |
| 应用 | Contents、StaticObjects、Lock、Unlock |
| 服务器 | CreateObject、MapPath、HTMLEncode、URLEncode、Execute、Transfer、ScriptTimeout、GetLastError |
常用函数
| 类别 | 函数 |
|---|---|
| 字符串 | Len、Left、Right、Mid、InStr、InStrRev、Replace、Split、Join、Trim、LTrim、RTrim、UCase、LCase、String、Space、StrReverse |
| 数学 | Abs、Int、Fix、Round、Rnd、Randomize、Sqr、Exp、Log |
| 日期 | Now、Date、Time、Year、Month、Day、Hour、Minute、Second、Weekday、DateAdd、DateDiff、DatePart、DateSerial、FormatDateTime |
| 类型 | CStr、CInt、CLng、CDbl、CDate、CBool、IsNull、IsEmpty、IsNumeric、IsDate、IsArray、IsObject、TypeName、VarType |
| 数组 | Array、Split、Join、UBound、LBound、Filter |
| 格式化 | FormatNumber、FormatCurrency、FormatPercent、FormatDateTime |
常用语句
ASP
<%
' 条件
If x > 0 Then
' ...
ElseIf x = 0 Then
' ...
Else
' ...
End If
' 多分支
Select Case n
Case 1 : Response.Write "一"
Case 2, 3 : Response.Write "二或三"
Case Else : Response.Write "其它"
End Select
' 循环
For i = 1 To 10 Step 2
Next
For Each item In collection
Next
Do While Not rs.EOF
rs.MoveNext
Loop
Do Until x > 10
x = x + 1
Loop
%>指令
ASP
<%@ Language="VBScript" CodePage="65001" %>
<% Option Explicit %>
<% Response.Buffer = True %>
<% Session.CodePage = 65001 %>
<% Response.Charset = "UTF-8" %>
<!-- #include virtual="/includes/funcs.asp" -->常见错误号
| 错误号 | 含义 | 处理 |
|---|---|---|
| 类型不匹配 | 对字符串做算术 | 先 CInt / CDbl |
| 变量未定义 | Option Explicit 下用了未声明变量 | Dim 声明 |
| 对象不支持此属性 | 调用了不存在的方法 | 查组件文档 |
| 权限被拒绝 | 写文件没有权限 | 给 IUSR 加写权限 |
| 文件未找到 | 路径错或文件不存在 | MapPath 检查 |
| 未指定的错误 | 数据库连接失败 | 查连接串与驱动 |
| 下标越界 | 数组或集合越界 | 先判 UBound / Count |
HTTP 状态码
ASP
<%
Response.Status = "404 Not Found"
Response.Status = "403 Forbidden"
Response.Status = "500 Internal Server Error"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "https://example.com/new"
%>