100个asp实例-helloword(1-5)

来源:半月设计 发布人:GuoBar 发布时间:2005-8-5 7:59:44 人气: 所属栏目:ASP研究-ASP
1.hello word!  

<%@ LANGUAGE = VBScript %>  
<HTML>  
<TITLE>  
Hello World  
</TITLE>  
<BODY>  
<%  
’以下循环输出Hello World字符串,字体由小变大  
for i=1 to 5  
    response.write "<font size=" & i & ">hello world</font><br>"  
next   
%>  
</BODY>  
</HTML>  

2.内部站点判断  

<%@ Language=VBScript %>  
<html>  
<title>  
本站主页  
</title>  
<body>  
<%  
’本例根据远程主机地址来进行判断,如果为本地  
’地址则进入欢迎页面,否则显示出错信息.  
dim address  
address = request.servervariables("REMOTE_ADDR")  
if address="127.0.0.21" then   
    ’如果为本地,则显示欢迎页面.  
    response.write "你好,欢迎进入本站点."  
else  
    ’否则显示出错信息.  
    response.write "对不起,你无权查看内部站点."  
end if  
%>  
</body>  
</html>  

3.测试WEB服务器  

<HTML>  
<HEAD>  
<TITLE>测试WEB服务器</TITLE>  
</HEAD>  
<BODY>  
<Script language=jscript runat=server>  
    response.write ("<table border=1>");  
    response.write ("<tr><td>脚本引擎</td><td>");  
    response.write (ScriptEngine()+"</td></tr>");  
    response.write ("<tr><td>编译版本</td><td>");  
    response.write (ScriptEngineBuildVersion()+"</td></tr>");  
    response.write ("<tr><td>主 版 本</td><td>");  
    response.write (ScriptEngineMajorVersion()+"</td></tr>");  
    response.write ("<tr><td>次 版 本</td><td>");  
    response.write (ScriptEngineMinorVersion()+"</td></tr>");  
    response.write ("</table>");  
</script>  
<Script language=vbscript runat=server>  
   response.write "<table border=1>"  
   response.write "<tr><td>脚本引擎</td><td>"   
   response.write ScriptEngine() & "</td></tr>"  
   response.write "<tr><td>编译版本</td><td>"   
   response.write ScriptEngineBuildVersion() & "</td></tr>"  
   response.write "<tr><td>主 版 本</td><td>"   
   response.write ScriptEngineMajorVersion() & "</td></tr>"  
   response.write "<tr><td>次 版 本</td><td>"   
   response.write ScriptEngineMinorVersion() & "</td></tr>"  
   response.write "</table>"  
</script>  
</body>  

4.生成随机字符串  

<%@ LANGUAGE = VBScript %>  
<html>  
<title>  
生成随机字符串  
</title>  
<body>  
<%  
Function gen_key(digits)  
’定义并初始化数组  
    dim char_array(80)  
 ’初始化数字  
    For i = 0 To 9  
        char_array(i) = CStr(i)  
    Next  
 ’初始化大写字母  
    For i = 10 To 35  
        char_array(i) = Chr(i + 55)  
    Next  
 ’初始化小写字母  
    For i = 36 To 61  
        char_array(i) = Chr(i + 61)  
    Next  
 Randomize   ’初始化随机数生成器。  
 do while len(output) < digits  
        num = char_array(Int((62 - 0 + 1) * Rnd + 0))  
        output = output + num  
    loop  
’设置返回值  
    gen_key    =    output  
End Function  
’把结果返回给浏览器  
response.write "本实例生成的十三位随机字符串为:"  
response.write "<center>"  
response.write gen_key(13)  
response.write "</center>"  
%>  
</body>  
</html>  

5.移动鼠标改变背景颜色  

<%@ Language=VBScript %>  
<html>  
<title>  
移动鼠标改变背景颜色  
</title>  
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>  
<!--  
function MakeColor(ThisColor) {  
document.bgColor = ThisColor;  
}  
//-->  
</SCRIPT>  
<center>  
<table cellspacing=2 Border="0">   
<tr>  
<%  
Dim I1, I2, I3 ’ Looping variables for RGB Color  
For I1 = 0 to 15 step 3  
For I2 = 0 to 15 step 3  
For I3 = 0 to 15 step 3  
Color = Hex(I1) & Hex(I1) & Hex(I2) & Hex(I2) & Hex(I3) & Hex(I3)  
%>  
<td bgcolor="#<%=Color%>">  
<a href="#" LANGUAGE=javascript OnMouseOver="return MakeColor(’#<%=Color%>’);">  
<img src="clear.gif" width=10 height=10 border="0"></a>  
</td>  
<%  
Next  
Next  
%>  
</tr>  
<tr>  
<%  
Next  
%>  
</tr>  
</table>  
</center>  
</html>  


生成时间:2006-5-27 12:34:03