Web >> Development >> ASP >>  How to use a template file, perform search and replace and generate a dynamic html page

This example, the ASP code does the following - read static html page monitor_hosts_wis.htm - searches for <head> and replace with <head> some other string - writes output to html response <% response.expires=-1 Set fs = Server.CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile(Server.MapPath("monitor_hosts_wis.htm"), 1) sHtml = f.ReadAll ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' search for <head> ' replace with <head><META HTTP-EQUIV="REFRESH" CONTENT="60"> ' <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> ' <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' sReplace = "<head>" & vbCrLf & _ "<META HTTP-EQUIV=""REFRESH"" CONTENT=""60"">" & vbCrLf & _ "<META HTTP-EQUIV=""PRAGMA"" CONTENT=""NO-CACHE"">" & vbCrLf & _ "<META HTTP-EQUIV=""CACHE-CONTROL"" CONTENT=""NO-CACHE"">" & vbCrLf sHtml = Replace(sHtml,"<head>",sReplace) Response.Write(sHtml) f.Close Set f=Nothing Set fs=Nothing %>