ASP generated static page mainly involves three aspects: template, parameters, FSO

Source: Internet
Author: User
fso| Static | template asp Generation static page mainly involves three aspects: template, Parameters, FSO.

1, Template: This is actually the framework of the page, the following is a template example:
############################## #这就是一个模板 ###############################
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> $title $</title>
<link href= "/blog/css/style1.css" rel= "stylesheet" type= "Text/css"/>
<meta name= "description" content= "$desc $"/>
<meta name= "keywords" content= "$keywords $"/>
<body>
<!--head-->
$top $////These are the substitution parameters
<!--head end-->
<table border= "0" cellpadding= "0" cellspacing= "0" width= "760" style= "margin-top:2px"; >
<tr>
&LT;TD width= "160" valign= "Top" bgcolor= "#eeeef2" style= "border-right:1px #ddd solid" >
$web _i$////These are replacement parameters
</td>
<!--the right side of the presentation-->
&LT;TD valign= "Top" bgcolor= "#eeeef2" style= "width:265px;height:20px;border-left:1px #fff solid;border-right:1px CCC SOLID ">
$pic $////These are the substitution parameters
</td>
&LT;TD valign= "Top" style= "border-left:1px #fff solid" bgcolor= "#eeeef2" >
$rec _text$////These are replacement parameters
</td>
</tr>
</table>
<!--column End-->
$b _ban$////These are replacement parameters
<table border= "0" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD width= "540" valign= "Top" style= "border-right:1px #ccc solid" >
$c _list$////These are replacement parameters
</td>
&LT;TD width= "218" valign= "Top" style= "border-left:1px #fff solid" bgcolor= "#eeeef2" >
$focus _text$////These are replacement parameters
</td>
</tr>
</table>
$link $////These are the substitution parameters
$bottom $////These are the substitution parameters
</body>

When we're making a dynamic page, it is also a good static frame, and then put the dynamic content in, and the template is not put into the dynamic content of the page, and these dynamic content is replaced by parameters, like the template above: $top $, $web _i$, $pic $, $rec _text$, $c _list $, $focu _text$, $link $, $bottom $, these parameters are their own definition, you can write any form, but it is best to use the word alphanumeric letters, these parameters are originally to display dynamic content where.
If you do not use a template, it needs to be made in a dynamic page, such as top=top "to output the content" &vbcrlf--(&vbcrlf, is to make the code another line), this is more cumbersome, because the original static framework should also be written inside.
If the template is generated, of course, these templates are to be stored in the database, the first to remove the template from the database:
############# #取栏目页面模板 ####################
Set Rs_m=server.createobject ("Adodb.recordset")
Sql= "Select content from MB where id=2"
Rs_m.open sql,conn,1,1
Main=rs_m ("content")
Rs_m.close
Set rs_m=nothing
Then you replace the parameters in the template one by one, such as the following;
#################### #原本的动态内容 #############
Response.Write "<div class=" "Badv" ">"
Set Rs_b=server. CreateObject ("Adodb.recordset")
Sql= "SELECT * from Add_banner where p_column= '" &column& "' and isselect= ' y ' and p_size= ' 760*80 '"
Rs_b.open sql,conn,1,1
If rs_b.eof and Rs_b.bof then
Response.Write " "
Else
Response.Write End If
Response.Write "</div>" &vbcrlf
##################### #生成静态页定义的动态内容 ############
b_ban= "<div class=" "Badv" ">"
Set Rs_b=server. CreateObject ("Adodb.recordset")
Sql= "SELECT * from Add_banner where p_column= '" &column& "' and isselect= ' y ' and p_size= ' 760*80 '"
Rs_b.open sql,conn,1,1
If rs_b.eof and Rs_b.bof then
b_ban=b_ban& " "
Else
b_ban=b_ban& "End If
b_ban=b_ban& "</div>" &vbcrlf
######################################
As you can see from the above, the original Response.Write is replaced by the B_ban=b_ban&amp, and then you need to replace the parameters in the template, we assign the template to main, in the template we define the parameter is $b_ban$, Then add the following words:
Main=replace (Main, "$b _ban$", B_ban), B_ban is dynamic content, B_ban can be defined arbitrarily, you can also be defined as ban, then Main=replace (Main, "$b _ban", Ban), The meaning here is b_ban to be clearer.
Other parameter substitutions are the same as this one. When all the parameters in the template are replaced, the FSO is needed to generate it.
The FSO is a built-in component of IIS, so you can use the FSO as long as the ISS is installed, which is defined in the following format:
Set FSO (this is also its own definition, where I define it as FSO) =server.createobject ("Scripting.FileSystemObject")//This defines the FSO
Set Fout=fso.createtextfile (Server.MapPath ("index.htm"))//Here is the definition Fout on the current server to generate the name index.htm (suffix is also defined by itself, can be HTML, Sthml static suffix) of the file, this file is currently blank.
Fout.write Main//write the contents of the static page so that the index.htm page, even if it is completely generated,
Fout.close//Close Fout
Set fout=nothing//Empty Fout
Set fso=nothing//Empty FSO
This completes the static page generated from the template.
If you do not use a template, you do not have to use replace but use Fout.wirte directly.
For example, we have top,body,bottom three parameters on this page, which is
Set FSO (this is also its own definition, where I define it as FSO) =server.createobject ("Scripting.FileSystemObject")//This defines the FSO
Set Fout=fso.createtextfile (Server.MapPath ("index.htm"))//Here is the definition Fout on the current server to generate the name index.htm (suffix is also defined by itself, can be HTML, Sthml static suffix) of the file, this file is currently blank.
Fout.write Top//write static page content
Fout.write body//write static page content
Fout.write bottom//write to static page content
Fout.close//Close Fout
Set fout=nothing//Empty Fout
Set fso=nothing//Empty FSO
This is done by directly generating a static 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.