Summary:
This article demonstrates several important applications of ASP server-side scripts.
Contents:
1. Traverse collections/objects
1.1 VBScript traverse form collections
1.2 JScript traverse forms Collection
2. Convert the value to a variable and assign a value
2.1 VBScript Convert the value to a variable and assign a value
2.2 JScript Convert the value to a variable and assign a value
3. Dynamic Included files
3.1 VBScript dynamic included files
3.2 JScript dynamic included files
shawl.qiu
2006-10-11
http://blog.csdn.net/btbtd
1. Traverse collections/objects
1.1 VBScript traverse form collections
linenum
for each temp in request.Form
response.write temp&": "&request.form(temp)
next
%>
1.2 JScript Traverse the form collection
linenum
for (var $e=new Enumerator (Request.Form); !$e.atEnd(); $e.moveNext()){
Response.Write($e.item() ':
' Request.Form($e.item( )));
}
%>
2. Convert the value to a variable and assign a value
2.1 VBScript Convert the value to a variable and assign a value
linenum
for each temp in request.Form
execute temp&"=request.form(temp)"
next
%>
2.2 JScript converts the value into a variable and Assignment
linenum
var $xml=new ActiveXObject("microsoft.xmldom");
$xml.load(Server.MapPath('config.xml'));
var $childNodes=$xml.documentElement.selectSingleNode('//siteconfig').childNodes
for ($e=new Enumerator($childNodes); !$e.atEnd(); $e .moveNext()){
eval($e.item().nodeName "=$e.item().text");
$xml=null;
Response.Write (sitekeywords);
%>
3. Dynamic include files
3.1 VBScript dynamic include files
linenum
function fInclude(filepath) ' sample call '''/// execute fInclude("include/system/language/"&sitefglang&"/main.asp") \'''
dim cnt
cnt=CreateObject("scripting.fileSystemObject" ).openTextFile(server.MapPath(filepath)).readall
cnt=replace(cnt," cnt=replace(cnt,chr(37)&">" ,"") fInclude=cnt
end function 'shawl.qiu code'
execute fInclude("include/system/language/"&sitefglang&"/main.asp")
%>
3.2 JScript dynamic include file
linenum
eval($dynInc('aj2.asp')); Response.Write($test);
function $dynInc($fl){
/* ---------------------------------- ---
* Server-side JScript dynamic include file By shawl.qiu
* sample call: eval($dynInc('aj2.asp'));
*--------- --------------------------*/
var $fso=new ActiveXObject("scripting.fileSystemObject");
var $fso=new ActiveXObject("scripting.fileSystemObject");
str=$fso.OpenTextFile(Server.MapPath($fl)).ReadAll();
$fso=null; return $str;
}
%>