|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
这次我为大家介绍的是我第一个用ASP做的程序----聊天室,很简朴,没用数据库,但是对于还未学到ADO的同志是个比较好的参考例子,这个例子基本包括了所以ASP的五个内置对象,但是有了聊天室的雏形,假如水平到家可以在此基础上做的强盛好看点好了,废话不说了,现在进入正题吧! 首先这个程序有四个部分组成,分别是index.asp,chat.asp,show.asp,input.asp首先调用chat.asp然后就可以运行了! 作为一个初学者,我觉得写一个程序整体观念很重要,也就是说你首先要确定要实现什么样的功能,然后再进行各个功能的分块和解决,那么作为一个简朴的聊天室我觉得首先要有一个登陆界面,登陆后进入一个聊天室的主界面,主界面又分为两个块,上面一块是聊天显示的内容,下面一块是聊天者写入的文字并进行发送。 确定好各个功能版块后,然后我们各个去实现!好,先解决登陆界面吧,这个轻易,html随便做个表单,我做的很简朴: <html> <head> <title>欢迎光临小型聊天室</title> <meta http-equiv=Content-Language content=zh-cn> </head> <body topmargin=150 bgcolor=ffffff> <table border=1 align="center" cellpadding=0 cellspacing=0 height=200> <tr> <td align=center >聊天室用户登陆</td> </tr> <tr> <td align=center height=162> <form method=POST action="chat.asp"> <table border=0 cellpadding=0 cellspacing=0> <tr> <td></td> </tr> <tr> <td width=37% align=center>用户名</td> <td width=63%> <input type="text"name="userid" size=19 maxlength="10" > </td> </tr> <tr> <td >密 码</td> <td> <input type="password" name="password" size=19 maxlength="30"> </td> </tr> <td> <p align=center><input type=submit value="登陆" name="submit"> <input type=reset value="重写" name=reset > </td> </tr> <tr> <td ></td> </tr> </table> </form> </td> </tr> <tr> <td align=center><a href=http://www.webjx.com target="_blank">www.webjx.com</a></td> </tr> </table> </body> </html> 好了,做好了这么个简朴的登陆页面后下面我们进入主页面的制作。 上面我们做了个简朴的登陆页面,现在开始做我们的主界面chat.asp: <% name=request.form("userid") password=request.form("password") response.cookies("cname")=name session("sname")=name if name=""then response.redirect"index.asp" end if %> <frameset rows=80%,20%> <frame name="show" src="show.asp"> <frame name="input" src="input.asp"> </frameset> 这个程序主要实现的是提取index.asp的表单数据,然后判定是否用户有填写用户名,假如没有回到登陆界面,同时设立了cookies和session变量以用于其他文件的调用。 做好了以后我们转入编写input.asp文件,也就是用户输入聊天内容的部分: <html> <head> <title>欢迎光临小型聊天室</title> </head> <body> <meta http-equiv=Content-Language content=zh-cn> <form method="post" action="show.asp" target="show"> <p><font=ffff00><%=request.cookies("cname")%></font> 说:<input type="text" name=putword size="82"> <input type="submit" name=formsubmit value="发送"> <input type="reset" name=formreset value="重发"> </font> </body> </html> 这段代码很简朴,有一个地方初学者可能会看不懂,target是实现将写入的内容送到show的框架,而不是被直接在自己的框架里!读者可以体会一下把target去掉,接下来我们做最后一个部分也就是show.asp部分 <% mytalk=trim(request.form("putword")) if mytalk<>""then application.lock application("show")="<font color=0000ff size=4>" & request.cookies("cname") & "</font>:" & "<font size=3>" & mytalk & "</font>" & "<br>" & application("show") application.unlock end if %> <html> <head> <title>欢迎光临小型聊天室</title> </head> <body> <meta http-equiv=Content-Language content=zh-cn> <pre> <%=application("show")%> </pre> </body> </html> 由于没有应用数据库,这段代码主要的部分是用application来实现对聊天内容进行共享好了,很简朴的一个聊天室做好了,呵呵!不要见笑啊! 返回类别: 教程 上一教程: 在ASP程序中实现数据库事务控制 下一教程: 列表项可上下移动的MULTIPLE列表 您可以阅读与"用ASP做个简朴聊天室"相关的教程: · 用ASP建立一个简朴的聊天室 · XMLHTTP+Javascript+Asp写得聊天室,无刷新实现(三) · XMLHTTP+JAVASCRIPT+ASP写得聊天室,无刷新实现(六) · XMLHTTP+Javascript+Asp写得聊天室,无刷新实现(二) · 用AGENT+ASP技术制作语音聊天室 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |