static | page | static asp2html with Templet
I want you to see the title so that you can imagine its function:
1,with Templet means that the resulting page schema will take on a set template, which I've described in a tutorial before, and I hope you'll be familiar with the template for ASP before you look at this tutorial. (Of course, do not see also no problem, this tutorial will also mention the essence of the:) Specific reference: http://www.cnbruce.com/blog/showlog.asp?cat_id=26&log_id=474
2,asp2html. Don't let me talk about the benefits of ASP into HTML, hehe, one of the most worth knowing is that static HTML pages and dynamic pages on the server's requirements to withstand much less, the same, static HTML search probability is much more than dynamic pages.
So the technical problem I need to deal with right now is:
1, how to implement template technology? (See the next article first)
2, how to achieve 2HTML technology?
3. How to combine template technology with 2HTML technology?
First, the technical principle analysis
1, template technology refer to www.cnbruce.com/blog/showlog.asp?cat_id=26&log_id=474
2,2html technology How to achieve it? How do I make an ASP page into HTML? The FSO component is generally thought of, because the component can create any new file format.
So what is the whole process of running?
A, provide information input page for information collection;
b, the acceptance information value first save the database, then the FSO to generate files;
C, the technical completion of the task to display the newly created HTML file path address.
There are several difficulties in the implementation of this technology:
Does the file generated by I,fso be placed directly in a large folder or in a subfolder that is updated daily? may be inaccurate, so understand: believe that the file generated through the FSO over time, the file will be more and more, management will be more and more chaotic ... Usually you may see some addresses such as www.xxx.com/a/2004-5-20/200405201111.html can be analyzed to create the current date of the folder. In this way, a day is a folder page content, view management also seems more reasonable.
I found a second problem when I tried to create a folder through the above methods. The first time through the FSO to create a folder named after the current date, no problem. When I have a new file to build, because it is the same program, it will execute the same folder. At this point, the FSO component will find that the path already exists ... Jam-_-! Continue processing, adding code to the first line:
Reference:
On Error Resume Next
Hey, to achieve self-deception, deceive the effect.
Of course the use of the rules is to determine whether the folder has no
Reference:
<%
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
if (FSO). FolderExists (Server.MapPath (folder)) then
' Judge if there's no deal.
Else
' Determine if a new folder is not present
Fso. CreateFolder (Server.MapPath (folder))
End If
%>
III, the folder is established, how to establish the file? This is mainly the generation of file names. Of course this will require you to write a function, the function is how to generate file name:)
Reference:
<%
function Makefilename (fname)
fname = FName ' before fname as variable, after fname for function parameter reference
fname = replace (fname, "-", "")
fname = replace (fname, "", "")
fname = replace (fname, ":", "")
fname = replace (fname, "PM", "")
fname = replace (fname, "AM", "")
fname = replace (fname, "a.m.", "")
fname = replace (fname, "PM", "")
Makefilename = fname & ". html"
End Function
%>
The reference function is:
<%fname = Makefilename (now ())%>
In fact, is the date of the day and the minutes of the name of the file.
IV, and finally, how do you view the generated files? Of course, you need to save the path to the generated file in the database and add it to the corresponding set of records. Of course, this is mentioned in the following database design.
3, the combination of template technology and 2HTML technology: Replace the value of special code in the template with the values received from the form, complete the template function, and generate HTML files for all the template codes that are eventually replaced. Note that the substitution should be able to completely change the format of the input data or the code that supports UBB.
Second, the database design
At present, database design needs two tables: one is to store the template data, one is to store the information content.
1, create a new database Asp2html.mdb
2, design a new database table C_moban
Field m_id (AutoNumber, primary key), Field m_html (Memo type).
and copy the following complete code to the M_html field
Reference:
<meta http-equiv= "Content-type" content= "text/html; Charset=hz ">
<title>cnbruce.com | Asp2html test</title>
<body leftmargin= "0" topmargin= "0" >
<table width= "100%" height= "100%" border= "0" cellpadding= "5" cellspacing= "2" >
<tr align= "Right" bgcolor= "#CCCCCC" >
<TD height= colspan= "2" > $cntop {logcontent}lt;/td>
</tr>
<TR valign= "Top" >
<TD width= "25%" bgcolor= "#e5e5e5" > $cnleft {logcontent}lt;/td>
<TD width= "74%" bgcolor= "#f3f3f3" > $cnright {logcontent}lt;/td>
</tr>
</table>
</body>
3, design a new database table C_news
Field c_id: Automatic numbering, primary key
Field C_title: Text type, saving article title
Field C_content: Memo type, saving article content
Field C_filepath: Text type, keeping the path address of the generated file
Field C_time: Date/Time type, default value: Now ()
Third, page requirements design
1, first create a folder that holds HTML pages
In the same directory, set up folder Newsfile, clips inside the main storage generated HTML pages, of course, the internal will also adopt a program to establish a date-named subfolder to facilitate browsing and management.
2, Function function page lib.asp
Reference:
<%
' function to generate file name
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, "a.m.", "")
fname = replace (fname, "PM", "")
Makefilename=fname & ". sHTML"
End Function
' A function that keeps 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 (a) & CHR (a), "<br>")
fstring = Replace (fstring, CHR (), "<br>")
HTMLEncode = fstring
End Function
%>
3, Database Connection page conn.asp
Complete the string concatenation method of the database
<%
Set conn = Server.CreateObject ("ADODB. Connection ")
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &server.mappath ("Asp2html.mdb")
Conn. Open ConnStr
%>
4, Information input page add.html
It's really simple: it's a form. Note that the action is to jump to addit.asp
Reference:
<form action= "addit.asp" method= "POST" >
Title:<input type= "text" name= "C_title" ><br>
Content:<br>
<textarea name= "C_co