After a period of ASP learning, the following we combine the content learned to build a simple chat room, although very simple, but you can use it to master a chat room to establish the basic process, and can constantly improve its function.
The following are the main steps:
1, add the code inside the Global.asa file. This section of code deals with the Application_OnStart event, in which a 15-element data is defined, and assigns it to a Application object's properties. The contents of the Global.asa file are as follows.
2, add the code to the aspchat.asp file. Note that this part of the code is added between the two horizontal lines in the home page, which is between two
in the text. The program first determines whether the application of the homepage is a "post" method, because in this case the method of submitting the window is "post" In general, the first time you apply for this homepage, the "Get" method is used. So if a "post" method is used, it means that a visitor is submitting his or her conversation to a new application, which is going to be done, because there is another conversation. Otherwise, the first time a visitor applies for this homepage, Didn't submit any conversations, so just have to show the current conversation.
a simple chat room
<% process input if Request.servervaria
Bles ("request_method") = "POST" then marked speaker if Len (Request ("txtwho") >0 then session ("Sswho") =request ("txtwho") End If
Block Application Object Application.Lock Create a local reference pointer mlcounter=application ("Gicounter") machats=application ("GaChats")
If the number of rows written is more than 10, restart the count. If Mlcoundter>9 then mlcoundter=0 End If Add user input, counter plus 1 machat (mlchounter) =session ("sswho") & ":" &request ("
Txtcents ") mlcounter=mlcounter+1 set the local variable to be valid within the scope of the application.
Applicati "Gicounter") =mlcounter application ("Gachats") =machat suppress Application object blockade Application.UnLock End If%> <% Write textarea if Application ("Gicounter") =0 then Lstemp=application ("Gachats") (0) Else for x=0 to application ("Gicounter") -1 lstemp=lstemp& "
" Application ("Gachats") (x) Next End If Response.white lstemp%>
3, and finally the content of the txtwho initialization. That is, when the viewer enters his or her own name once, the user does not have to enter it again, in order to distinguish each of the different browsers, where the "session" object is used. Using session ("sswho") Record the name of the visitor. The following code is written directly below the above code into the aspchat.asp.
Complete. Just put 2, 3 steps before and after the code to add the complete HTM file code and then save as aspchat.asp on it, this is a very simple ASP chat room program, we can continue to strengthen its function as the study of the in-depth!