Web程序设计实验报告
题目:聊天室
学生姓名: 吴美冬
学 号: 1021111222
班 级: 10211112
指导教师: 吴建东
2013年 3 月 7日
一. 实验目的
熟练掌握web课程的相关知识,知道如何运用web编程, 并编写简单的系统。
二、实验内容
1、题目:聊天室
2、功能要求:
注册、登录
创建聊天室
进入退出聊天室
基本的聊天功能
三、实验步骤
聊天室系统总共有8个网页,分别是log.html,check.asp,check1.asp,speak.asp,display.asp,mark.asp,register.html,logout.asp。其中,cheak.asp是用来验证log.html的,check.asp是用来验证register.html的。
1、代码
log.html的代码为:
<!doctype html>
<html>
<head>
<title>聊天系统</title>
<!--meta charset="utf-8"-->
<script language="javascript">
function checkdata(){
if form1.user.value=empty then
alert("用户名不能为空!")
form1.user.focus
elseif form1.pwd.value=empty then
alert("密码不能为空!")
end if
}
</script>
</head>
<body>
<h1 align="center"><font color="#000080" face="华文新魏" size="8">聊天系统</font></h1>
<form method="post" action="check.asp" name="form1" >
<table align="center" >
<tr>
<td>用户名:</td><td><input type="text" name="user"></td>
</tr>
<tr>
<td>密码:</td><td><input type="password" name="pwd"></td>
</tr>
<tr>
<td><input type="submit" value="登录" name="log" onclick="checkdata"></td>
<td> <a href="register.html">注册</a></td>
</tr>
</table>
</form>
</body>
</html>
check.asp的代码为:
<%
dim user,pwd,log,regis
user=request("user")
pwd=request("pwd")
log=request("log")
%>
<%
dim rs,str,cn,sqlstr,p
set cn=server.createobject("ADODB.connection")
str="provider=microsoft.jet.oledb.4.0;data source="&server.mappath("./db/db1.mdb")
cn.open str
set rs=server.createobject("adodb.recordset")
sqlstr="select user,password from db1 where user='"&user&"'"
rs.open sqlstr,cn,1,3
if rs.eof then
response.write "<script language='javascript'>alert('用户名不存在');;location.href='log.html'</script>"
elseif rs("password")<>pwd then
response.write "<script language='javascript'>alert('密码不正确');;location.href='log.html'</script>"
end if
rs.close
set cn=nothing
%>
<%
dim userinf
session("name")=request("user")
userinf=session("name")&"在"&time&"进入聊天室"
application.lock
application("mark")=userinf&"<br>"&application("mark")
application.unlock
%>
<html>
<head>
<title>聊天室主界面</title>
</head>
<frameset rows="30%,*" frameborder="yes">
<frame src="speak.asp" target="_self">
<frameset cols="60%,*" frameborder="yes">
<frame src="display.asp">
<frame src="mark.asp">
</frameset>
</frameset>
</html>
register.html的代码为:
<!doctype html>
<html>
<head>
<title>用户注册</title>
<!--meta charset="utf-8"-->
</head>
<body>
<h1 align="center"><font color="#000080" face="华文新魏" size="8">用户注册</font></h1>
<form name="form2" action="check1.asp" method="post">
<table align="center">
<tr>
<td>请输入用户名:</td><td><input type="text" name="user1"></td>
</tr>
<tr>
<td>请输入密码:</td><td><input type="password" name="pwd1"></td>
</tr>
<tr>
<td><input type="submit" value="注册" name="B"></td><td colspan="2"><input type="reset" value="重置" name="B1"></td>
</tr>
</table>
</form>
</body>
check1.asp的代码为:
<%
dim user,pwd,log,regis,rs1,driver,cn1,sqlstr1,dbpath
user=request("user1")
pwd=request("pwd1")
log=request("B")
set cn1=server.createobject("ADODB.connection")
driver="Driver={Microsoft Access Driver (*.mdb)};"
dbpath="DBQ="&server.mappath("./db/db1.mdb")
cn1.open driver&dbpath
set rs1=server.createobject("adodb.recordset")
sqlstr1="select user,password from db1 where user='"&user&"'"
rs1.open sqlstr1,cn1,1,3
if not rs1.eof then
response.write "<script language='javascript'>alert('用户名存在,请重新输入!');;location.href='register.html'</script>"
else
sqlstr1="insert into db1(user,password) values('"&user&"','"&pwd&"')"
response.write "注册成功!,请到登陆界面登录!"
cn1.execute sqlstr1
end if
rs1.close
set cn1=nothing
%>
speak.asp的代码为:
<!doctype html>
<html>
<head>
<title>speak page</title>
<script language="javascript">
function go(){
history.go(0)
}
</script>
</head>
<%
dim username,speak,information
if not request("message")="" then
username=session("name")
speak=request("message")
information=""&username&"说:"&speak&""
application.lock
application("talk")=information&"<br>"&application("talk")
applicatin.unlock
end if
%>
<body bgcolor="lightgreen">
<form method="post" action="speak.asp" name="form3">
<%=session("name")&","%>请输入要说的话,或<a href="logout.asp" target="_parent">退出聊天室</a><br>
<input type="text" name="message" size="60">
<input type="submit" value="发送" onclick="return go();">
</form>
</body>
</html>
display.asp的代码为
<!doctype html>
<html>
<head>
<title>display the information</title>
<meta http-equiv="refresh" content="10">
</head>
<body>
<%
response.write application("talk")
%>
</body>
</html>
mark.asp的代码为:
<!doctype html>
<html>
<head>
<meta http-equiv="refresh" content="10">
</head>
<body bgcolor="grey">
<%
response.write application("mark")
%>
</body>
</html>
logout.asp的代码为:
<%
dim name,str
name=session("name")
str=name&"在"&time&"退出"
application("mark")=str&"</br>"&application("mark")
response.redirect "log.html"
%>
2、界面
登录界面如下:
注册界面如下:
功能主界面如下:
数据库文件截图如下:
四、实验总结
通过此次实验,我比较熟练的掌握了web的一些基本知识,
知道了如何设计一个web系统,以及在设计过程中会遇到哪些问题,以及如何解决这些问题的方法。