Technical summary of ASP generating static HTML file

Source: Internet
Author: User
Tags file system
Write HTML code to a file and generate an. HTML-formatted file

Write HTML code to a file and 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: "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= "" >
& Lt;input name= "title" value= "title" Size=26>
<br>
<textarea name= "Body" >Body</textarea>
<br>
<br>
<input type= "Submit" name= "submit" value= "Generate HTML" >
</form>< /p>

2, but according to the above method to generate HTML file is very inconvenient, 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
<HTML>
<title> $title $ by aspid.cn</title>
<body>
$body $
</body>
<%
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!" "

'//Release File system objects
Set htmlwrite=nothing
Set fso=nothing
%>



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.