| 网站首页 | 资讯 | 影音 | 图片 | 论坛 | 模拟驾考 | 免费取名算命 | 瓷都工具 | 留言本 | 域名 | 瓷都商城 | 汇款 | 
|
资讯首页
|
瓷都德化
|
站内新闻
|
影视剧情
|
汽车世界
|
网络文摘
|
周易八卦
|
教程技巧
|
房产信息
|
您现在的位置: 瓷都热线|诚信中国:“一就是一”(1941.CN) >> 资讯 >> 教程技巧0 >> 网络编程 >> 正文 登录 注册
专 题 栏 目
  • 四川汶川8.0级强震
  • 机动车驾驶员考试资料
  • 高考试题及答案
  • 最 新 热 门
     德化又添3个地理标志证明
     [组图]期待!德化龙门湖
     [组图]德化:“绿色动脉
     [图文]德化:造莲花美景
     [图文]德化:编织小网格
     [图文]德化龙门滩龙门湖
     [图文]福建德化县美湖镇
     德化白瓷艺术展亮相深圳
     [组图]“世界瓷都·润养
     德化:前妻婚内举债近8万
    最 新 推 荐
     [组图]期待!德化龙门湖
     [组图]德化:“绿色动脉
     [图文]德化龙门滩龙门湖
     [图文]福建德化县美湖镇
     [组图]德化各种花卉相继
     [组图]福建德化九仙山迎
     [图文]德化石牛山惊现双
     [组图]千年古瓷都德化的
     [组图]警方连捣5传销窝点
     [组图]福建民俗博物馆办
    相 关 文 章
    没有相关资讯
    查看ASP源代码的方法         ★★★
    查看ASP源代码的方法
    作者:不详 文章来源:不详 更新时间:2003-12-8 2:29:03
    【声明:转载此信息在于传递更多信息,其内容表达的观点并不代表本站立场,由这些信息所产生的一切后果本站不负任何责任。如果您对本信息有什么意见,欢迎和本站联系,谢谢!】http://CiDu.Net

    我们都知道asp这一类的服务器端处理的程序,其好处之一就是只向客户端输出标准的Html流。因此可以起到向客户隐藏细节的作用。也就是说当我们在浏览器中键入asp程序的网址后只能看见标准的Html文件,而不能看见asp的内容。但有时,例如在一个asp的教学站点,我们有必要显示asp文件的内容,或者你愿意将你的原代码与人享,通过一个程序将代码显示出来。
    下面是我编写的一个asp程序,view_code.asp,它提供两种提交方式:一种是用表格提交,即你知道了该源文件的物理地址(类似于:c:\asp_source\test.asp的形式)。一种是采用get方式提交(类似于:<a href="view_code.asp?code_path=<%=server.mappath(request.servervariables("PATH_INFO"))%>&cgi_type=asp">点击此处查看原代码</a>)。另外它还支持两种cgi脚本,一种是asp,一种是php。

    代码段:
    <%
    on error resume next
    '忽略程序执行中的错误,在程序的最后统一处理。
    %>
    <%
    function rt_min(num1,num2)
    '该子程序用于返回两数中不等于零的最小数。
    if num1=0 and num2=0 then
    rt_min=-1
    elseif num1=0 then
    rt_min=num2
    elseif num2=0 then
    rt_min=num1
    elseif num1<num2 then
    rt_min=num1
    else
    rt_min=num2
    end if
    end function
    %>
    <%
    function line_check(strline,cgi_type)
    '该子程序用于检查输入段中是否包含有"<%、%>、<script或</script的特殊字符
    dim cgi_flag
    if cgi_type="php" then
    cgi_flag="?"
    else
    cgi_flag="%"
    end if
    '定义的cgi_flag用于代表php和asp的不同标识符
    line_check=0
    itemp=0
    ipos=instr(strline,"<"&cgi_flag)
    if rt_min(ipos,itemp)=ipos then
    itemp=ipos
    line_check=1
    end if
    ipos=instr(strline,cgi_flag&">")
    if rt_min(ipos,itemp)=ipos then
    itemp=ipos
    line_check=2
    end if
    ipos=instr(1,strline,"<"&"script",1)
    if rt_min(ipos,itemp)=ipos then
    itemp=ipos
    line_check=3
    end if
    ipos=instr(1,strline,"<"&"/script",1)
    if rt_min(ipos,itemp)=ipos then
    itemp=ipos
    line_check=4
    end if
    end function
    %>
    <%
    sub printhtml(strline)
    '该子过程用于打印不含有上述四种特殊标记的行
    ispace=len(strline)-len(ltrim(strline))
    i=1
    while(mid(strline,i,1))=chr(9)
    ispace=ispace+5
    i=i+1
    wend
    '统计空白的数量
    if ispace>0 then
    for i=1 to ispace
    response.write("&nbsp;")
    next
    end if
    ipos=instr(strline,"<")
    if ipos then
    response.write(left(strline,ipos-1))
    response.write("&lt;")
    '用&lt;来替代<,使浏览器不解释<>中的标记
    strline=right(strline,len(strline)-ipos)
    call printhtml(strline)
    '自调用,直到没有<的出现
    else
    response.write(strline)
    end if
    end sub
    %>
    <%
    sub printline(strline,iflag,cgi_type)
    '该自过程用于根据line_check的返回值分别处理
    dim cgi_flag
    if cgi_type="php" then
    cgi_flag="?"
    else
    cgi_flag="%"
    end if
    select case iflag
    case 0
    call printhtml(strline)
    case 1
    ipos=instr(strline,"<"&cgi_flag)
    call printhtml(left(strline,ipos-1))
    response.write("<font color=#ff0000>")
    response.write("&lt;"&cgi_flag)
    strline=right(strline,len(strline)-ipos-1)
    call printline(strline,line_check(strline,cgi_type),cgi_type)
    '自调用,直到没有四种特殊标记的出现
    case 2
    ipos=instr(strline,cgi_flag&">")
    call printhtml(left(strline,ipos-1))
    response.write(cgi_flag&"&gt;")
    response.write("</font>")
    strline=right(strline,len(strline)-ipos-1)
    call printline(strline,line_check(strline,cgi_type),cgi_type)
    case 3
    ipos=instr(1,strline,"<"&"script",1)
    call printhtml(left(strline,ipos-1))
    response.write("<font color=#00ff00>")
    response.write("&lt;"&"script")
    strline=right(strline,len(strline)-ipos-6)
    call printline(strline,line_check(strline.cgi_type),cgi_type)
    case 4
    ipos=instr(1,strline,"<"&"/script>",1)
    call printhtml(left(strline,ipos-1))
    response.write("lt;"&"/script"&"&gt;")
    response.write("</font>")
    strline=right(strline,len(strline)-ipos-8)
    call printline(strline,line_check(strline,cgi_type),cgi_type)
    case else
    response.write("error")
    end select
    end sub
    %>
    <html>
    <head>
    <title> view cgi_code(.asp or .php) </title>
    </head>
    <body>
    <form action="view_code.asp" method="POST">
    请输入路径:<input type=text name="code_path">
    请选择类型:<select name="cgi_type">
    <option value="asp">asp</option>
    <option value="php">php</option>
    </select>
    <input type=submit>
    </form>
    <hr>
    <%
    if vartype(request.servervariables("HTTP_REFERER")) then
    '判断该页面是否是由其他的页面申请提交,若用户是直接在浏览器中输入地址
    而来的,则HTTP_REFERER环境变量应该没有被初始化
    if request.servervariables("REQUEST_METHOD")="POST" then
    code_path=request.form("code_path")
    cgi_type=request.form("cgi_type")
    response.write("下面的代码来自表格的提交:"&"<br>")
    response.write("路径为:"&code_path&"<br>")
    elseif request.servervariables("REQUEST_METHOD")="GET" then
    code_path=request.querystring("code_path")
    cgi_type=request.querystring("cgi_type")
    response.write("下面的代码来自"&code_path&"的提交:"&"<br>")
    response.write("路径为:"&code_path&"<br>")
    end if
    '根据提交方式的不同显示不同的提示
    set fileobject=server.createobject("Scripting.FileSystemObject")
    if fileobject.fileexists(code_path) then
    '检查要打开的文件是否存在
    set stream=fileobject.opentextfile(code_path,1,false,0)
    while not stream.atendofstream
    stroutput=stream.readline
    call printline(stroutput,line_check(stroutput,cgi_type),cgi_type)
    '将该文件的每一行都分别交给printline来处理
    response.write("<br>")
    wend
    set stream=nothing
    else
    response.write("不能打开文件"&"<br>")
    end if
    end if
    %>
    </body>
    </html>
    <%
    '下面的代码为统一的错误处理段,它根据程序运行时产生的错误代码来分别处理
    if err.number<>0 then
    response.write("error"&"<br>")
    response.write("错误代码:"&err.number&"<br>")
    response.write("错误描述:"&err.description)
    end if
    %>

    最后,我在给出一个引用该程序的测试页面
    <html>
    <head>
    <title>显示代码的测试页面</title>
    </head>
    <body>
    <a href="view_code.asp?code_path=<%=server.mappath(request.servervariables
    ("PATH_INFO"))%>&cgi_type=asp">点击此处查看该页的源码</a>
    </body>
    </html>


    声明:以上信息资料大都是网上搜集而来,版权归作者,如有版权问题请留言告知我将马上改正。
    文中所提到的各种观点只是原文观点,各种说法未经一一确认。并不代表本站认可此观点!!
    资讯录入:ahui    责任编辑:ahui 
  • 上一篇资讯:

  • 下一篇资讯:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    点击数:759
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
        没有任何评论