ASP is entered rank tutorial Ⅱ :A simple visitors' book
Tuesday, March 03, 2009 by rain
Begin us from this chapter will by simple,Use a file to store the tutorial that visits the visitors' book program that leave a message to enter us.Write a such visitors' book,We are roughly OK from the following three move will finish.
Measure one:Design to leave a message first the webpage that expresses sheet (be like:Guestbook1.asp,This need not I preached here?) .See figure below:
Measure two:Good in the design leave a message after the table is simple,The ASP program that we begin to undertake writing handling leaving a message.
We should write the ASP program that processing leaves a message,The most serious problem is how to come true access leave a message.And in ASP program,Should access a file,We must establish FileSystemObject target (the document that this object basically uses at reading to take Unicode or ASCII yard) .And should establish FileSystemObject target,The statement that we can make in order to falls again:
= CREATEOBJECT of example of object of SET of of ("SCRIPTING.FILESYSTEMOBJECT" )
The method of FileSystemObject object includes:CreateTextFile and OpenTextFile:
CreateTextFile:Build name of a file,Return object of a TextStream to offer you to read keep a file
OpenTextFile:After the file that opens to already existed builds object of a TextStream to write a file to be being built and open to be able to offer editorial document with offerring you to read,The methodological WriteLine(that we can call TextStream object to fall finally keeps information into the document that reachs to already was opened and line feed) read with methodological ReadLine(take the group that already opened a file information) will access a file.
because of this,Want implementation to access the ASP program that leave a message,We can be conceived as follows roughly:
establishs FileSystemObject target first;Call OpenTextFile to open a file to perhaps call CreateTextFile to found new document next through this object,Establish TextStream target;The WriteLine that we undertake calling TextStream boy or girl friend again finally and ReadLine undertake access a file.After solving this main problem,The ASP program that we can leave a message processing writes place to show: of
%26lt;%
Name = Request("Name" ) )
Email = Request("Email" )
Subject = Request("Subject" )
Memo = Request("Memo" )
' from leave a message watch sheet obtains data
If Name = "" Or Email = "" Or Subject = "" Or Memo = "" Then
Response.Write " inputs casing to cannot be blank! Response.Write " inputs casing to cannot be blank!!
Response.End
End If
Whether does the each input casing with ' examination simple table have information to input,If leave available input casing to was not filled,show demonstrative information:"Input casing cannot be blank! "Stop to execute the order below.?
Line1 = " leaves a message person:"%26 Name
Line1 = Line1 %26 String(5, " " )
Email = "%26lt;A HREF=mailto:" %26amp; Email %26amp; %26quot;%26gt;%26quot; %26amp; Email %26amp; %26quot;%26lt;/ A%26gt; %26quot;
Line1 = Line1 %26 "Email?"%26 Email %26 "%26lt;BR%26gt; %26quot;
Line2 = " advocate problem:"%26 Subject %26 "%26lt;BR%26gt; %26quot;
Memo = Replace(Memo, vbCrLf, vbCrLf,, %26lt;BR%26gt;%26quot; )
Line3 = "%26lt;TABLE BORDER=1%26gt;%26lt;TR%26gt;%26lt;TD%26gt; %26quot;
Line3 = Line3 %26 " your leave a message:"%26 Memo %26 "%26lt;/ TD%26gt;%26lt;/ TR%26gt;%26lt;/ TABLE%26gt; %26quot;
When Line4 = " :"%26 Now()
The indication format that ' definition leaves a message,Leave a message among them information rises with message convention.
On Error Resume Next
If carry out the ReadAll below,' avoids (read take all news that already opened a file) when,The case that cannot read the program error that takes information to be caused happens,Because this joins this to be used at oversight all mistakes.
Set Fso = Server.CreateObject("Scripting.FileSystemObject" ) Application.Lock
TxtPath = Server.MapPath("book1.txt" )
NewPath = Server.MapPath("newbook.txt" )
Fso.MoveFile TxtPath, newPath
Set Fin = Fso.OpenTextFile(NewPath, , true)
Set Fout = Fso.CreateTextFile(TxtPath)
' establishs FileSystemObject target,Lock up decide Application object,Do not let two any person that get online be carried out at the same time leave a message operation,Be built at the same time and open object of a TextStream,Point to should operate to going actually,The text Book1.txt that is used at leaving a message to record.
Fout.WriteLine Line1
Fout.WriteLine Line2
Fout.WriteLine Line3
Fout.WriteLine Line4
Fout.WriteLine "%26lt;Hr%26gt; %26quot;
Fout.WriteLine Fin.ReadAll
' leave a message in the file that branch keeps the information in expressing sheet to already was opened.
Fin.Close
Fso.DeleteFile NewPath, true
Application.UnLock
Response.Redirect "guestbook1.asp "
' is shut and delete Gbookold.txt,Remove next the lock of Application object is decided,Again how-to client carries a browser to arrive new Web page Guestbook1.asp.
%%26gt;
to your notebook afore-mentioned code COPY,Notice:Should write down will ally %26quot; %26lt; %26quot; the blank space take out that adds more at the back of the symbol,Put into file Manage1.asp next.
Measure three:The design leaves a message page
leaves a message because of what we want this visitors' book show in leave a message below watch sheet,So we can go to COPY of code of the following HTML the final area of Guestbook1.asp.
%26lt;Html%26gt;
%26lt;Head%26gt;
%26lt;Meta Http-equiv= %26quot;Content-Type%26quot; Content= %26quot;text/html; Charset=gb2312%26quot; %26gt;
%26lt;Title%26gt; your leave a message%26lt;/ Title%26gt;
%26lt;Link Rel= "stylesheet" Href= " . . / Images/Text.css%26quot; %26gt;
%26lt;/ Head%26gt;
%26lt;Body TEXT= %26quot;#000000%26quot; BGCOLOR= %26quot;#FFFFFF%26quot; BACKGROUND= %26quot;b01.jpg%26quot; %26gt;
%26lt;H2 ALIGN= %26quot;CENTER%26quot; %26gt; your leave a message%26lt;/ H2%26gt;
%26lt;Hr Noshade Color= %26quot;red%26quot; %26gt;
%26lt;! - - #include File= "book1.txt "- - %26gt;
%26lt;/ Body%26gt;
%26lt;/ Html%26gt;
%26lt;% Response.End %%26gt;
After completes afore-mentioned all step,The executable fictitious list that maintains Guestbook1.asp and Manage1.asp existence WEB server (be like:Below Asp/) ,The means that uses HTTP in the browser undertakes browsing,Be like:Http://yourcomputername/asp/guestbook1.asp.Look!So simple,You had had your visitors' book.Still do not try at once!
...
Measure one:Design to leave a message first the webpage that expresses sheet (be like:Guestbook1.asp,This need not I preached here?) .See figure below:
Measure two:Good in the design leave a message after the table is simple,The ASP program that we begin to undertake writing handling leaving a message.
We should write the ASP program that processing leaves a message,The most serious problem is how to come true access leave a message.And in ASP program,Should access a file,We must establish FileSystemObject target (the document that this object basically uses at reading to take Unicode or ASCII yard) .And should establish FileSystemObject target,The statement that we can make in order to falls again:
= CREATEOBJECT of example of object of SET of of ("SCRIPTING.FILESYSTEMOBJECT" )
The method of FileSystemObject object includes:CreateTextFile and OpenTextFile:
CreateTextFile:Build name of a file,Return object of a TextStream to offer you to read keep a file
OpenTextFile:After the file that opens to already existed builds object of a TextStream to write a file to be being built and open to be able to offer editorial document with offerring you to read,The methodological WriteLine(that we can call TextStream object to fall finally keeps information into the document that reachs to already was opened and line feed) read with methodological ReadLine(take the group that already opened a file information) will access a file.
because of this,Want implementation to access the ASP program that leave a message,We can be conceived as follows roughly:
establishs FileSystemObject target first;Call OpenTextFile to open a file to perhaps call CreateTextFile to found new document next through this object,Establish TextStream target;The WriteLine that we undertake calling TextStream boy or girl friend again finally and ReadLine undertake access a file.After solving this main problem,The ASP program that we can leave a message processing writes place to show: of
%26lt;%
Name = Request("Name" ) )
Email = Request("Email" )
Subject = Request("Subject" )
Memo = Request("Memo" )
' from leave a message watch sheet obtains data
If Name = "" Or Email = "" Or Subject = "" Or Memo = "" Then
Response.Write " inputs casing to cannot be blank! Response.Write " inputs casing to cannot be blank!!
Response.End
End If
Whether does the each input casing with ' examination simple table have information to input,If leave available input casing to was not filled,show demonstrative information:"Input casing cannot be blank! "Stop to execute the order below.?
Line1 = " leaves a message person:"%26 Name
Line1 = Line1 %26 String(5, " " )
Email = "%26lt;A HREF=mailto:" %26amp; Email %26amp; %26quot;%26gt;%26quot; %26amp; Email %26amp; %26quot;%26lt;/ A%26gt; %26quot;
Line1 = Line1 %26 "Email?"%26 Email %26 "%26lt;BR%26gt; %26quot;
Line2 = " advocate problem:"%26 Subject %26 "%26lt;BR%26gt; %26quot;
Memo = Replace(Memo, vbCrLf, vbCrLf,, %26lt;BR%26gt;%26quot; )
Line3 = "%26lt;TABLE BORDER=1%26gt;%26lt;TR%26gt;%26lt;TD%26gt; %26quot;
Line3 = Line3 %26 " your leave a message:"%26 Memo %26 "%26lt;/ TD%26gt;%26lt;/ TR%26gt;%26lt;/ TABLE%26gt; %26quot;
When Line4 = " :"%26 Now()
The indication format that ' definition leaves a message,Leave a message among them information rises with message convention.
On Error Resume Next
If carry out the ReadAll below,' avoids (read take all news that already opened a file) when,The case that cannot read the program error that takes information to be caused happens,Because this joins this to be used at oversight all mistakes.
Set Fso = Server.CreateObject("Scripting.FileSystemObject" ) Application.Lock
TxtPath = Server.MapPath("book1.txt" )
NewPath = Server.MapPath("newbook.txt" )
Fso.MoveFile TxtPath, newPath
Set Fin = Fso.OpenTextFile(NewPath, , true)
Set Fout = Fso.CreateTextFile(TxtPath)
' establishs FileSystemObject target,Lock up decide Application object,Do not let two any person that get online be carried out at the same time leave a message operation,Be built at the same time and open object of a TextStream,Point to should operate to going actually,The text Book1.txt that is used at leaving a message to record.
Fout.WriteLine Line1
Fout.WriteLine Line2
Fout.WriteLine Line3
Fout.WriteLine Line4
Fout.WriteLine "%26lt;Hr%26gt; %26quot;
Fout.WriteLine Fin.ReadAll
' leave a message in the file that branch keeps the information in expressing sheet to already was opened.
Fin.Close
Fso.DeleteFile NewPath, true
Application.UnLock
Response.Redirect "guestbook1.asp "
' is shut and delete Gbookold.txt,Remove next the lock of Application object is decided,Again how-to client carries a browser to arrive new Web page Guestbook1.asp.
%%26gt;
to your notebook afore-mentioned code COPY,Notice:Should write down will ally %26quot; %26lt; %26quot; the blank space take out that adds more at the back of the symbol,Put into file Manage1.asp next.
Measure three:The design leaves a message page
leaves a message because of what we want this visitors' book show in leave a message below watch sheet,So we can go to COPY of code of the following HTML the final area of Guestbook1.asp.
%26lt;Html%26gt;
%26lt;Head%26gt;
%26lt;Meta Http-equiv= %26quot;Content-Type%26quot; Content= %26quot;text/html; Charset=gb2312%26quot; %26gt;
%26lt;Title%26gt; your leave a message%26lt;/ Title%26gt;
%26lt;Link Rel= "stylesheet" Href= " . . / Images/Text.css%26quot; %26gt;
%26lt;/ Head%26gt;
%26lt;Body TEXT= %26quot;#000000%26quot; BGCOLOR= %26quot;#FFFFFF%26quot; BACKGROUND= %26quot;b01.jpg%26quot; %26gt;
%26lt;H2 ALIGN= %26quot;CENTER%26quot; %26gt; your leave a message%26lt;/ H2%26gt;
%26lt;Hr Noshade Color= %26quot;red%26quot; %26gt;
%26lt;! - - #include File= "book1.txt "- - %26gt;
%26lt;/ Body%26gt;
%26lt;/ Html%26gt;
%26lt;% Response.End %%26gt;
After completes afore-mentioned all step,The executable fictitious list that maintains Guestbook1.asp and Manage1.asp existence WEB server (be like:Below Asp/) ,The means that uses HTTP in the browser undertakes browsing,Be like:Http://yourcomputername/asp/guestbook1.asp.Look!So simple,You had had your visitors' book.Still do not try at once!
...