Design a message book with ASP

Source: Internet
Author: User
Tags date comments html page insert interface net readline reset
Design

First of all, we make a message thin, first make an input screen interface effect, that is, generate the Message Input screen HTML page, and then in these HTML source code to add ASP script, I get the HTML code below.

* FileName: book.htm

<title> Message Book </title>


<body bgcolor= "#BED9FC" background= "Images/bg.gif"


<p align= "center" >Height= "" "> </p>

<p align= "center" >[<a href= "disp.asp" I want to see the message board </a>] [<a Href=]. /index.asp "> back home </a>] </p>

<form method= "POST" action= "book.asp"
<input type= "hidden" name= "task" value= "Insert" ><div "left" <table>
<tr>
<TD align= "right" > name </td>
The <td> </td>
<td> <input name= "name" size= "+" </td>
</tr>
<tr>
<TD align= "right" sex </td>
The <td> </td>
<td> <input name= "Sex" size= "+" </td>
</tr>
<tr>
<TD align= "Right" from the </td>
The <td> </td>
<td> <input name= "from" size= "+" </td>
</tr>
<tr>
<TD align= "right" homepage URL </td>
<td>
<td> <input name= "url" size= "+" </td>
</tr>
<tr>
<TD align= "Right"


E-Mail </td>
<td>
<td> <input name= "Email" size= "+" </td>
</tr>
<tr>
<TD align= "right" > message </td>
<TD colspan= "2" ><textarea wrap= "Off" name= "comments" cols= "$" rows= "9" > </textarea> </td>
</tr>
<tr>
<td> </td>
<TD colspan= "2" > <dl>
<DD align= "center" > <input type= "Submit" value= "I have written"
<input type= "reset" value= "re-write" > </dd>
</dl>
</td>
</tr>
</table>
</div>
</form>

<p align= "center" > </p>
</body>


You can click here to look at the effect of this interface (you need to emphasize that the HTML code is still completely non-functional) you can save it as a book.htm, and then open it with FRONTPAGE98, open, you can view the page of the input form of the attribute, in this message book. We use two files to process, one is book.asp, the other is disp.asp, the former is an input interface, the latter is a display interface, used to display message information.

Now talk about book.htm, let's get a look at the role of that input form, its action object is itself, book.asp (Wait a moment to rename book.htm to book.asp) This file, that is. After the form is submitted, it is handled by itself. In this form, there are several text input boxes, which are name,sex,from,url,email, and multiple lines of text input boxes comments.

Now rename book.htm to book.asp and add ASP code to the file. as follows: (single quotation marks represent an ASP's analysis, the compiler is not processed.)

*book.asp

<% @language = "VBScript"%>
<%
"To determine the request, when the client requests the file, such as direct input URL: http://active.silversand.net/index.htm This way, you will produce a GET request information. When the form is submitted (the form is set to post), it will produce a POST request, and now judge whether the book.asp file is the user to open the page in the browser, or the user submits the data this action, in order to process.
If Request.ServerVariables ("request_method") = "POST" Then
' Here the page is judged by the user submitting the form, so the registration message is processed.
' Create a server instance of a file component

Set Fsfilesys=createobject ("Scripting.FileSystemObject")
' Open Text file Server.MapPath ('/') is the true path to return to the server's release directory, i.e., c:\Inetpub\wwwroot this path and then "/realchat/book/book.txt" Is the path that is based on this path.

Set Mytext=fsfilesys.opentextfile (Server.MapPath ("/") & "/realchat/book/book.txt")
' Read all the contents of the text file and save it in the TEMP variable.

Temp=mytext.readall
Mytext.close
' Whether you need to add content

If Request ("task") = "Insert" Then
' Get the values of the items in the form

Tname=request.form ("name")
Tsex=request.form ("Sex")
Temail=request.form ("email")
Turl=request.form ("url")
Tfrom=request.form ("from")
Tcomments=request.form ("comments")
Ttime= "#&@" &time
If Len (tcomments) <2 Then
%>
<font size= "4" color= "Red"

<p align= "Center" > I'm sorry! You haven't left a message yet. <a Href= "Book.asp" to return to </a> </font> <%
Else
If Lcase (left (turl,7)) <> http://Then
Turl= "http://" &turl
End If
Turl=lcase (Turl)
' Recreate the data file and overwrite the original.

Set Mytext=fsfilesys.createtextfile (Server.MapPath ("/") & "/realchat/book/book.txt")
Mytext.writeline (Tname)
Mytext.writeline (Tsex)
Mytext.writeline (Temail)
Mytext.writeline (Turl)
Mytext.writeline (Tfrom)
Mytext.writeline (tcomments)
Mytext.writeline (Ttime)
Mytext.writeline (date)
Mytext.writeline (Temp)
Mytext.close
%>
<script language= "JavaScript" >
document.write ("</script>
<%

End If
' At this point, the message has been saved in the file Book.txt

End If

Else
' The first time you enter the input screen, so the contents of the HTML file are displayed.
%>

<title> Message Book </title>
<% colorbg= "#BED9FC"%>

<body bgcolor= "<% =colorbg%>" background= "Images/bg.gif"


<p align= "center" >Height= "" "> </p>

<p align= "center" >[<a href= "disp.asp" I want to see the message board </a>] [<a Href=]. /index.asp "> back home </a>] </p>

<form method= "POST" action= "book.asp"
<input type= "hidden" name= "task" value= "Insert" ><div "left" <table>
<tr>
<TD align= "right" > name </td>
The <td> </td>
<td> <input name= "name" size= "+" </td>
</tr>
<tr>
<TD align= "right" sex </td>
The <td> </td>
<td> <input name= "Sex" size= "+" </td>
</tr>
<tr>
<TD align= "Right" from the </td>
The <td> </td>
<td> <input name= "from" size= "+" </td>
</tr>
<tr>
<TD align= "right" homepage URL </td>
<td>
<td> <input name= "url" size= "+" </td>
</tr>
<tr>
<TD align= "Right"


E-Mail </td>
<td>
<td> <input name= "Email" size= "+" </td>
</tr>
<tr>
<TD align= "right" > message </td>
<TD colspan= "2" ><textarea wrap= "Off" name= "comments" cols= "$" rows= "9" > </textarea> </td>
</tr>
<tr>
<td> </td>
<TD colspan= "2" > <dl>
<DD align= "center" > <input type= "Submit" value= "I have written"
<input type= "reset" value= "re-write" > </dd>
</dl>
</td>
</tr>
</table>
</div>
</form>

<p align= "center" > </p>
</body>
<%
End If
%>
Now to disp.asp this file, this file mainly completes extracts the file content from the Book.txt, then rebuilds the HTML code to display the message content.

The code is as follows:

<% @language = "VBScript"%>


<title> Message Book </title>

<body background= "Images/back.gif"

<p align= "center" ><%
' Open Data file

Set Fsfilesys=createobject ("Scripting.FileSystemObject")
Set Mytext=fsfilesys.opentextfile (Server.MapPath ("/") & "/realchat/book/book.txt")
Tname=mytext.readline
%> </p>

<p align= "center" >[<font color= "#00FFFF" size= "4" ><a href= "book.asp" > > I want to write a message. </a> </font>][<font color= "#00FFFF" ><a href =".. /index.asp "> back home </a> </font>] </p>

<table width= "600" >
<%
Do While Tname <> "Line1"
' Line-by-row readout (LINE1) is the end of file flag

Tsex=mytext.readline
Temail=mytext.readline
Turl=mytext.readline
Tfrom=mytext.readline
%>
<tr>
<td> </td>
</tr>
<tr>
' <%= expression%> is the result of output to the client

<th colspan= "2" align= "left", Name:% =tname%> <br>
Sex:% =tsex%> <br>
E-mail:<a href= "mailto:<% =temail%>" ><% =temail%> </a> <br>
Home url:<a href= "<% =turl%>" target= "_blank" ><% =turl </a> <br>
From:% =tfrom%> </th>
</tr>
<tr>
<th align= "left" bgcolor= "<% =colorbg%>" ><font color= "Red" message: </font> </th>
<th align= "left" bgcolor= "<% =colorbg%>" ><%
Tcomments=mytext.readline
Do While INSTR (tcomments, "#&@") =0
%>
<% =tcomments%>
<br>
<%
Tcomments=mytext.readline
Loop
Ttime=mid (tcomments,4)
Tdate=mytext.readline
%> </th>
</tr>
<tr>
<th colspan= "2" align= "left" time:% =ttime%> <br>
Date:% =tdate%> </th>
</tr>
<tr>
<td> <br>
<%
Tname=mytext.readline
Loop
Mytext.close
%> </td>
</tr>
</table>

<p> <br>
<br>
</p>
</body>
Well, carefully put down the source file, their own constantly modified, constantly testing, so that the study is very good to see the content of Book.txt.

*book.txt content, there is a message inside

Little Hu
Man
Realplay@163.net
Http://realplay.163.net
Foshan
Warmly welcome to "Thai confidence dynamic chat room virtual community" into the test use order, heartfelt thanks to you for your arrival, in the test process has any questions or good suggestions, please tell me.
Yesky invites you to join in!
Webmaster

Wak@21:51:15
99-7-13
Line1

This message is very simple, but I feel very intimate, more than those "modern" such as echocardiography message thin style, much simpler.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.