这一节主要是讲asp的server对像.里面包含了一些常用技巧.如何创建另一个组件的实例化。一般用来操作其他组件。比如ado,fso(filesystemobject)...等等...其实在这一节里面比较好理解的应该是htmlencode和urlencode这二个编码函数。就是将字符转换成其他的编码。没别的啦。。。最难理解的应该就是execute,当用它调用其他的页面时。是先执行被调用页面然后才会回来自己的代码块继续执行下面的代码(好像也不太难理解)。哈哈。反正asp还是比较简单的..好了现在看代码
示例图:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>server对像的学习</title>
</head>
<body>
<%
xx=request.Form("abcxd")
if request.Form("radiobutton")="scripttimeout" then
server.ScriptTimeout=xx '设置scripttimeout超时的时间.-1就是永远不超时(不推荐)
for i=1 to 5 '循环五次
response.write "执行第" & i & "秒<br>"
times=now '取得当前时间
do 'dateadd函数返回一个被改变了的日期
loop until now>dateadd("s",1,times) '每循环一次会停一秒.那么整个程序必须要五秒才能运行完毕。
next '那么如果你把超时时间设置成四秒的话。那么程序就会造成没有执行完就被结束了。然后就会返回一个超时的错误给你
response.Write("执行完成")
end if
if request.form("radiobutton")="createobject" then
'set 变量名=server.createobject(对像名) 创建对像时记住要用到set不要忘了哦
set conn=server.createobject("ADODB.connection") '这里创建了一个数据库对像。用来链接数据库的。就先学这些。
'到时候再加深
response.write "你创建了一个(adodb.connection)数据库对像名存为:conn"
end if
if request.form("radiobutton")="mappath" then '取路径
response.write server.mappath(request.form("abcxd")) '从文件名输出当前所得到的路径
end if
if request.Form("radiobutton")="htmlencode" then '将字符转换.第一个地址是经过html语言执行后才显示.而第二是直接显示出代码
response.Write "示例<a href=http://www.abcxd.com>点击</a><br>"
response.write server.HTMLEncode(request.Form("abcxd"))
end if
if request.form("radiobutton")="urlencode" then
response.Write "示例<a href=http://www.abcxd.com>点击</a><br>"
response.write server.urlencode(request.form("abcxd"))
end if
if request.form("radiobutton")="execute" then
server.execute("被呼叫的.asp")
response.write " -如果呼叫成功会出现(abcxd)"
'execute的意思是执行其他的asp文件.当执行了此句。会先运行完后才会返回当前asp文件执行他下面的代码
'被呼叫的.asp代码
'<%
'response.write "abcxd"
'% > 请把中间的空格去掉
end if
%>
<form id="form1" name="form1" method="post" action="">
<p>
<label>
请输入:
<input name="abcxd" type="text" value="" size="45"/>
</label>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</p>
<label>
<input type="radio" name="radiobutton" value="scripttimeout" onclick="abcxd.value='6'"/>
对像超时设置</label>
<label>
<input type="radio" name="radiobutton" value="createobject" />
对像创建
<input type="radio" name="radiobutton" value="mappath" onclick="abcxd.value='.'"/>
显示路径</label>
<label>
<input type="radio" name="radiobutton" value="htmlencode" onclick="abcxd.value='示例<a href=http://www.abcxd.com>点击</a>'"/>
html编码设置</label>
<label> <br />
<input type="radio" name="radiobutton" value="urlencode" onclick="abcxd.value='示例<a href=http://www.abcxd.com>点击</a>'"/>
url编码设置</label>
<label>
<input type="radio" name="radiobutton" value="execute" />
execute方法</label>
</form>
</body>
</html>
其他地方转过来的
| 方法 | 说明 |
| Createobject | 创建一个ACTIVEX组件实例 |
| MapPath | 将指定的虚拟路径转换为真实的路径,这里的虚拟路径指的是WEB服务器所建立的虚拟路径。 |
| HTMLEncode | 将字符串应用为HTML编号 |
| URLEncode | 将字符串应用为URL编码 |
原创文章如转载,请注明:转载自心动吧黑客BLOG [ http://www.abcxd.com/abcxd/ ]
本文链接地址:http://www.abcxd.com/abcxd/abcxdArticle/asp/server.html