HTML generated by ASP

Source: Internet
Author: User
Currently, two tables are required for Database Design: one for storing template data and the other for storing information.

 

1. Create a new database asp2html. MDB

2. design the new database table c_moban
Field m_id (automatic number, primary keyword); field m_html (Remarks type ).
Copy the following complete code to the m_html field.

<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = Hz">
<Title> cnbruce. com | asp2html test </title>
</Head>
<Body leftmargin = "0" topmargin = "0">
<Table width = "100%" Height = "100%" border = "0" cellpadding = "5" cellspacing = "2">
<Tr align = "right" bgcolor = "# cccccc">
<TD Height = "20" colspan = "2"> $ cntop $ </TD>
</Tr>
<Tr valign = "TOP">
<TD width = "25%" bgcolor = "# e5e5e5"> $ cnleft $ </TD>
<TD width = "74%" bgcolor = "# f3f3f3"> $ cnright $ </TD>
</Tr>
</Table>
</Body>
</Html>

3. Design the new database table c_news

Field c_id: automatic number, primary keyword
Field c_title: text type. Save the article title.
Field c_content: remarks type. Save the article content.
Field c_filepath: text type, retain the path address of the generated file
Field c_time: date/time type; default value: Now ()

Create newsfile to store the website generated

Now we officially start. I will write down the code of my work, and you will understand more experiments.

Conn. asp

**************************************** *

Index. asp

<% @ Language = "VBScript" codePage = "936" %>
<! -- # Include file = "conn. asp" -->
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>

<Body>

<%
Sql1 = "select * From c_news"
Set RS1 = server. Createobject ("ADODB. recordset ")
Rs1.open sql1, Conn, 1, 1
Do while not rs1.eof
%>
<Table width = "300" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<TD> <% = RS1 ("c_id") %> </TD>
<TD> <a href = "<% = RS1 (" c_filepath ") %>"> <% = RS1 ("c_title") %> </a> </TD>
<TD> <a href = "Del. asp? C_id = <% = RS1 ("c_id") %> "> Delete </a> </TD>
<TD> <a href = "Chang. asp? C_id = <% = RS1 ("c_id") %> "> modify </a> </TD>
</Tr>
</Table>
<P>
<%
Rs1.movenext
Loop
Rs1.close
Set RS1 = nothing
%>
</P>
<P> Add a <a href = "Add. asp"> dd. asp </a> </P>
</Body>
</Html>
***************************

Lib. asp

<%
'Function for generating file names
Function makefilename (fname)
Fname = fname
Fname = Replace (fname ,"-","")
Fname = Replace (fname ,"","")
Fname = Replace (fname ,":","")
Fname = Replace (fname, "PM ","")
Fname = Replace (fname, "am ","")
Fname = Replace (fname, "Morning ","")
Fname = Replace (fname, "Afternoon ","")
Makefilename = fname & ". shtml"
End Function

'Functions that keep the data format unchanged
Function htmlencode (fstring)
Fstring = Replace (fstring, ">", "> ")
Fstring = Replace (fstring, "<", "<")
Fstring = Replace (fstring, CHR (32 ),"")
Fstring = Replace (fstring, CHR (13 ),"")
Fstring = Replace (fstring, CHR (10) & CHR (10), "<br> ")
Fstring = Replace (fstring, CHR (10), "<br> ")
Htmlencode = fstring
End Function
%>

**********************

Del. asp

<! -- # Include file = "conn. asp" -->

<%
C_id = request. querystring ("c_id ")
SQL = "select * From c_news where c_id =" & c_id
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 2, 3

Filepath = RS ("c_filepath ")
Set FSO = Createobject ("scripting. FileSystemObject ")
FSO. deletefile (server. mappath (filepath ))
Set FSO = nothing

Rs. Delete
Rs. Close
Set rs = nothing
Conn. Close
Set conn = nothing
%>

<% Response. Redirect ("index. asp") %>

**************************************** *********

Add. asp

<% @ Language = "VBScript" codePage = "936" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>

<Body>
<Form action = "addit. asp" method = "Post">
Title: <input type = "text" name = "c_title"> <br>
Content: <br>
<Textarea name = "c_content" rows = "8" Cols = "30"> </textarea> <br>
<Input type = "Submit" value = "add">
<Input type = "reset" value = "reset">
</Form>

</Body>
</Html>
***************************************

Chang. asp

<! -- # Include file = "conn. asp" -->
<! -- # Include file = "Lib. asp" -->

<% C_id = request. querystring ("c_id") %>

<%
If request ("SS") = "LB" then
C_title = request. Form ("c_title ")
C_content = request. Form ("c_content ")
C_id = request. Form ("c_id ")
C_filepath = request. Form ("c_filepath ")

Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * From c_news where c_id =" & c_id
Rs. Open SQL, Conn, 3, 2
RS ("c_title") = c_title
RS ("c_content") = c_content
RS ("c_time") = now ()
Rs. Update
Rs. Close
Set rs = nothing
%>

<% 'Open the template code and convert the special code to the accept value.
Sql1 = "select m_id, m_html from c_moban where m_id = 1"
Set RS1 = server. Createobject ("ADODB. recordset ")
Rs1.open sql1, Conn, 1, 1
Mb_code = RS1 ("m_html ")
Rs1.close
Set RS1 = nothing
Conn. Close
Set conn = nothing
C_title = htmlencode (c_title)
C_content = htmlencode (c_content)
Mb_code = Replace (mb_code, "$ cntop $", now ())
Mb_code = Replace (mb_code, "$ cnleft $", c_title)
Mb_code = Replace (mb_code, "$ cnright $", c_content)
%>

<% 'Generate an HTML page
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set fout = FSO. createtextfile (server. mappath (c_filepath ))
Fout. writeline mb_code
Fout. Close
%>
<% Response. Redirect ("index. asp") %>
<% End if %>

<%
If c_id <> "" then
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * From c_news where c_id =" & c_id
Rs. Open SQL, Conn, 1, 1
C_id = RS ("c_id ")
C_filepath = RS ("c_filepath ")
C_title = RS ("c_title ")
C_content = RS ("c_content ")
End if
%>

<Form action = "Chang. asp? Ss = LB "method =" Post ">
Title: <input type = "text" name = "c_title" value = <% = c_title %> <br>
Content: <br>
<Textarea name = "c_content" rows = "8" Cols = "30"> <% = c_content %> </textarea> <br>
<Input type = "Submit" value = "change" name = "Submit">
<Input type = "reset" value = "reset">
<Input name = "c_id" type = "hidden" value = "<% = c_id %>">
<Input name = "c_filepath" type = "hidden" value = "<% = c_filepath %>">
</Form>

**************************************

Addit. asp

<% 'Fault tolerance handling
On Error resume next
%>

<! -- # Include file = "conn. asp" -->
<! -- # Include file = "Lib. asp" -->

<% 'Accept transfer value
C_title = request. Form ("c_title ")
C_content = request. Form ("c_content ")
%>

<% ': Generate the HTML file name, create a folder, and specify the file path.
Fname = makefilename (now () 'makefilename is a custom function
Folder = "newsfile/" & date ()&"/"
Filepath = folder & fname
%>

<% 'Keep the accept value and path to the database table
SQL = "select * From c_news"
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 3, 2
Rs. addnew
RS ("c_title") = c_title
RS ("c_content") = c_content
RS ("c_filepath") = filepath
Rs. Update
Rs. Close
Set rs = nothing
%>

<% 'Open the template code and convert the special code to the accept value.
Sql1 = "select m_id, m_html from c_moban where m_id = 1"
Set RS1 = server. Createobject ("ADODB. recordset ")
Rs1.open sql1, Conn, 1, 1
Mb_code = RS1 ("m_html ")
Rs1.close
Set RS1 = nothing
Conn. Close
Set conn = nothing
C_title = htmlencode (c_title)
C_content = htmlencode (c_content)
Mb_code = Replace (mb_code, "$ cntop $", now ())
Mb_code = Replace (mb_code, "$ cnleft $", c_title)
Mb_code = Replace (mb_code, "$ cnright $", c_content)
%>

<% 'Generate an HTML page
Set FSO = server. Createobject ("scripting. FileSystemObject ")
FSO. createfolder (server. mappath (folder ))
Set fout = FSO. createtextfile (server. mappath (filepath ))
Fout. writeline mb_code
Fout. Close
%>

The article is successfully added. <a href = "index. asp"> browse </a>
*******************************

Haokunla

Let's take a look.

 

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.