ASP-generated static HTML file technology

Source: Internet
Author: User

Web page generation of static HTML file has many advantages, such as the creation of HTML Web pages are included in the search engine, not only included in the quick also included in the whole. The front desk is out of data access, reduces pressure on database access, and speeds up Web page opening.

Like Www.aspid.cn Main station on the use of Tsys to generate HTML files!
So Yin Qing recently to generate HTML more interested, read a lot of articles, but also a little harvest.

1, the following example directly uses the FSO to write HTML code to a file and then generate an. HTML-formatted file

<%
filename= "test.htm"
If Request ("Body") <> "then
Set fso = Server.CreateObject ("Scripting.FileSystemObject")
Set htmlwrite = FSO. CreateTextFile (Server.MapPath ("&filename&"))
Htmlwrite.write Htmlwrite.write" <body> output title content: " & Request.Form ("title") & "<br/> Output Body content:" & Request.Form ("Body") & "</body> Htmlwrite.close
Set fout=nothing
Set fso=nothing
End If
%>
<form name=" form "method=" post "Action=" ""
<input name= "title" value= "title" SIZE=26>
<br>
? <textarea name= "Body" > Body</textarea>
<br>
? <br>
? <input type= "Submit" name= "submit" value= "Generate HTML" >
</form>

2, but it's very inconvenient to generate HTML files in the above way, the second approach is to use template technology to replace the value of special code in the template with a value accepted from the form or database field, complete the template function, and generate an HTML file for all the template code that is eventually replaced. This technique is used more, Most CMS uses this type of method.
Template.htm '//template file
<title> $title $ by aspid.cn</title>
<body>
$body $
</body>

Testtemplate.asp '//Generate HTML
<%
Dim Fso,htmlwrite
Dim Strtitle,strcontent,strout
'//Create File system objects
Set fso=server.createobject ("Scripting.FileSystemObject")
'//Open page template file, read template content
Set Htmlwrite=fso. OpenTextFile (Server.MapPath ("template.htm"))
Strout=f.readall
Htmlwrite.close

strtitle= "generated page title"
strcontent= "generated Web page content"

'//Replace the tag in the template with the real content
Strout=replace (Strout, "$title $", strtitle)
Strout=replace (Strout, "$body $", strcontent)

'//Create a static page to be generated
Set Htmlwrite=fso. CreateTextFile (Server.MapPath ("test.htm"), true)

'//write page content
Htmlwrite. WriteLine Strout
Htmlwrite.close

Response.Write "Generate static page success!" "

Total 2 page: previous 1 [2] Next page



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.