< script language="vbscript" runat="server" > sub application_onstart() dim lchars(10) application("gchars")=lchars application("gcounter")=0 end sub < /script >
---- 2.确定处理ASP的方式:当用户第一次请求这个ASP文件时,用的是GET方法,然后,当用户输入完谈话内容后提交时用的是POST方法,在这里表单是向自身提交的,所以这个ASP文件会被再次请求,我们通过测试Request . ServerVariales(“Request_Method”)变量来确定文件被请求的方式:IF Request . ServerVariales(“Request_Method”)=“POST” then
IF len(request(“txtname”)) >0 then Session(“ssname”)=request(“txtname”) End if < h5 >您的姓名: < input type=“type” name=“txtname” length=“20” value=< %=session(“ssname”)% > >
if application("gcounter")=0 then lstemp=application("gchars")(0) else for x=0 to application("gcounter")-1 lstemp=lstemp ; "< br >" ; application("gchars")(x) next end if
---- 最后,用Response.write方法将lstemp变量的值写到客户的浏览器中去:
response.write lstemp
---- 下面给出Default.asp的完整代码:
< %response.expires=0 response.buffer=true% > < html >< head >< title >Chat sample< /title >< /head > < body >< center > < h3 >我的聊天室< /h3 >< /center >< hr > < % if request.servervariables("request_method")="POST" then if len(request("txtname")) >0 then session("ssname")=request("txtname") end if application.lock mcounter=application("gcounter") mchars=application("gchars") if mcounter >9 then mcounter=0 end if mchars(mcounter)=session("ssname") ; ":" ; request("txttalk") mcounter=mcounter+1 application("gcounter")=mcounter application("gchars")=mchars application.unlock end if % > < % if application("gcounter")=0 then lstemp=application("gchars")(0) else for x=0 to application("gcounter")-1 lstemp=lstemp ; "< br >" ; application("gchars")(x) next end if response.write lstemp % > < hr >< center > < form action="default.asp" method=post name="aspform" > < b >< a href="default.asp" > 更新显示< /a >< /b > < h5 >发言: < input type="text" name="txttalk" size="70" >< br > < h5 >您的姓名: < input type="text" name="txtname" length="20" value=< %=session("ssname")% > > < input type="submit" name="cmdpost" default="true" value="发送" > < /form >< /center >< /body >< /html >