By shawl. Qiu
Abstract:
This article demonstrates several important applications of ASP server scripts.
Directory:
1. Traverse collection/Object
1.1 VBScript traversal form set
1.2 JScript traversal form set
2. Convert the value to a variable and assign a value to it.
2.1 VBScript convert a value to a variable and assign a value
2.2 JScript convert a value to a variable and assign a value
3. dynamically include files
3.1 VBScript dynamic File Inclusion
3.2 JScript dynamic File Inclusion
Shawl. Qiu
2006-10-11
Http://blog.csdn.net/btbtd
1. Traverse collection/Object
1.1 VBScript traversal form set
Linenum
<%
For each temp in request. Form
Response. Write temp & ":" & request. Form (temp)
Next
%>
1.2 JScript traversal form set
Linenum
<%
For (VAR $ e = new enumerator (request. form );! $ E. atend (); $ E. movenext ()){
Response. Write ($ E. Item () + ': <br/>' + request. Form ($ E. Item ()));
}
%>
2. Convert the value to a variable and assign a value to it.
2.1 VBScript convert a value to a variable and assign a value
Linenum
<%
For each temp in request. Form
Execute temp & "= request. Form (temp )"
Next
%>
2.2 JScript convert a value to a variable and assign a value
Linenum
<%
VaR $ xml = new activexobject ("Microsoft. xmldom ");
$ XML. Load (server. mappath ('config. xml '));
VaR using childnodesusing using xml.doc umentelement. 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. dynamically include files
3.1 VBScript dynamic File Inclusion
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, "<" & CHR (37 ),"")
CNT = Replace (CNT, CHR (37) & "> ","")
Finclude = CNT
End function 'awl. Qiu Code'
Execute finclude ("include/system/Language/" & sitefglang & "/Main. asp ")
%>
3.2 JScript dynamic File Inclusion
Linenum
<%
Eval ($ dyninc ('aj2. asp '));
Response. Write ($ test );
function $ dyninc ($ FL) {
/* -------------------------------------- \
* the JScript on the server dynamically contains the file by shawl. qiu
* Sample call: eval ($ dyninc ('aj2. ASP ');
\ * ---------------------------------- */
var $ FSO = new activexobject ("scripting. fileSystemObject ");
$ STR = $ FSO. opentextfile (server. mappath ($ FL )). readall ();
$ STR = $ Str. replace (/\ <\ % | \ % \>/g, '');
$ FSO = NULL;
return $ STR;
}< BR >%>