服务端 vbscript 与 jscript 几个相同特性的写法
摘要:本文演示了asp服务端脚本的几个重要应用.
1. 遍历集合/对象
1.1 vbscript 遍历表单集合
linenum
<%
for each temp in request.form
response.write temp&": "&request.form(temp)
next
%>
1.2 jscript 遍历表单集合
linenum
<%
for (var $e=new enumerator(request.form); !$e.atend(); $e.movenext()){
response.write($e.item()+':<br/> '+request.form($e.item()));
}
%>
2. 转变量值为变量, 并赋值
2.1 vbscript 转变量值为变量并赋值
linenum
<%
for each temp in request.form
execute temp&"=request.form(temp)"
next
%>
2.2 jscript 转变量值为变量并赋值
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. 动态包含文件
3.1 vbscript 动态包含文件
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 'shawl.qiu code'
execute finclude("include/system/language/"&sitefglang&"/main.asp")
%>
3.2 jscript 动态包含文
linenum
<%
eval($dyninc('aj2.asp'));
response.write($test);
function $dyninc($fl){
/* ------------------------------------/
* 服务端 jscript 动态包含文件 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;
}
%>
新闻热点
疑难解答