ASP学习笔记
这几天在学ASP,虽然学习过程很顺利,但感觉对这门语言没什么兴趣,自己更习惯于JSP的那一套风格,下面的笔记希望可以帮助JSP的程序员能马上上手ASP,如果你想深入学习ASP,下面的笔记并不适合你.
ASP中选择语句,循环语句示例
================================================================
<%
if dd>400 then response.write "aaa"
else response.write "bbb"
end if
%>
<%
for j=1 to 10
response.write"ccc"
next
%>
<%
dim a
a=11
select case a
case 1,2,3,4 response.write "Hello"
case 5,6,7,8 response.write "Hi"
case 9,10,11,12 response.write "hey"
end select
%>
<%
dim a
a=1
do while a<10
response.write "hello<br>"
a=a+1
loop
%>
<%
dim b
b=1
do
response.write "hello"
b=b+1
loop while b<10
%>
<%
for a=1 to 10 step 2
response.write "hello<br>"
next
%>
for each next .............
<%
dim a
a=11
select case a
case 1,2,3,4 response.write "Hello"
case 5,6,7,8 response.write "Hi"
case 9,10,11,12 response.write "hey"
end select
%>
================================================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
JavaScript代码 可以写在<% %>里面,但通常放在<script type="text/JavaScript"> </script>
语句末尾有分号
区分大小写
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ASP默认使用的脚本语言是VBScript,
指定为JavaScript
<%@ language=JScript%>
注释:
=================================================
单行
' notice
Response.write now() 'notice
多行
<!-- -->
=================================================
VBScript 有两种过程 Sub 与 Function,Sub无返回值,Function有返回值
Sub过程
===========================================================
<html>
<head>
<title></title>
<script language="VBScript">
sub alert()
msgbox "Hello World"
end sub
</script>
</head>
<body>
<script language="VBScript">
call alert() <!-- use call -->
</script>
</body>
</html>
===========================================================
Function过程
===========================================================
<html>
<head>
<title></title>
<script language="VBScript">
Function add(a,b)
add = a+b
end Function
</script>
</head>
<body>
<script language="VBScript">
dim c
c = add(1,2)
msgbox "1 + 2 = " & c
</script>
<p> hello ! everyone</p>
</body>
</html>
===========================================================
总结
如果是不带参数的Sub或者Function 调用时使用 call 函数名() 或者直接写 函数名
直接写函数名,则不能带括号
ASP仅具有OOP的部分特性
Response对象
=======================================
<%
response.write
%>
<%=
%>
=======================================
response.end()
停止向页面输出数据
response.redirect()
网页重定向
Response的数据集合Cookies
Response.Cookies语句必须写在HTML标记之前
====================================================
<%
lasttime = request.cookies("lt")
response.cookies("lt") = now
%>
<html>
<head>
<title></title>
</head>
<body>
<%
response.write "Last Time you visit: " & lasttime & "<br><br><br>"
response.write "This Time you visit: " & now
%>
</body>
</html>
====================================================
request对象
====================================================
可以把浏览器收集的信息发送给服务器
HTML中表单提交数据的方式
No.1 Get
需要用 Request.QueryString获取
限制长度
No.2 Post
需要用 Request.Form获取
不限制信息的长度
====================================================
RecordSet对象有PageSize PageCount AbsolutePage(当前页)属性,用于分页显示
加载ASP页面
<!-- #include file="ConnectionDB.asp" -->
例如把连接数据库的基本信息放在ConnectionDB.asp
????????????????????????????????????????
con rs 对象的关闭
<%
rs.Close()
set rs = nothing //释放内存
con.Close()
set con = nothing //释放内存
%>
????????????????????????????????????????
特别注意一下
============================================
在ASP中,声明与赋初值是不能一起做的
例如:
Dim No = "1" 这是错误的
一定要分成两句
Dim No
No = "1"
============================================
P.S. 我写的一些ASP例子,都是很简单的
http://www.fs2you.com/files/a468ccde-3527-11dd-961d-0014221f3995/