• asp初学者常用的代码


    1.获得系统时间:
    <%=now()%>
    2.取得来访用的ip:
    <%=request.servervariables("remote_host")%>
    3.获得系统,浏览器版本:
    <script>
    window.document.write("版本:"+navigator.appname+navigator.appversion+" browser.")
    </script>
    4.去除ie混动条:
    <body scroll="no"> 
    <body style="overflow-y:hidden">
    5.进入网站,跳出广告 :
    <script language="javascript">
    <!-- 
    <!-- 注意更改文件所在路径-->
    window.open(''http://www.xxxxxx.com'','''',''height=200,width=300,top=0,left=30'');
    // -->
    </script>
    6.随机数:
    <%randomize%>
    <%=(int(rnd()*n)+1)%>
    n为可改变数
    7.向上混动代码:
    <marquee direction="up" scrolldelay="200" style="font-size: 9pt; color: #ff0000; line-

    height: 150%; font-style:italic; font-weight:bold" scrollamount="2" width="206"

    height="207" bgcolor="#ffff00">hhhhhhhhhhhhhhhhhhh</marquee>
    8.自动关闭网页:
    <script language="javascript">
    <!--
    settimeout(''window.close();'', 10000); //60秒后关闭
    // -->
    </script>
    <p align="center">本页10秒后自动关闭,请注意刷新页面</p>
    9.随机背景音乐:
    <%randomize%>
    <bgsound src="mids/<%=(int(rnd()*60)+1)%>.mid" loop="-1">

    可以修改数字,限制调用个数,我这里是60个.
    10.自动刷新本页面:
    <script> 
    <!--

    var limit="0:10"

    if (document.images){ 
    var parselimit=limit.split(":") 
    parselimit=parselimit[0]*60+parselimit[1]*1 

    function beginrefresh(){ 
    if (!document.images) 
    return 
    if (parselimit==1) 
    window.location.reload() 
    else{ 
    parselimit-=1 
    curmin=math.floor(parselimit/60) 
    cursec=parselimit%60 
    if (curmin!=0) 
    curtime=curmin+"分"+cursec+"秒后重刷本页!" 
    else 
    curtime=cursec+"秒后重刷本页!" 
    window.status=curtime 
    settimeout("beginrefresh()",1000) 

    }

    window.onload=beginrefresh 
    file://--> 
    </script>

    11.access其他数据库 连接:
    <%
    option explicit
    dim startime,endtime,conn,connstr,db
    startime=timer()
    '更改其他数据库 名字
    db="data/dvbbs5.mdb"
    set conn = server.createobject("adodb.connection")
    connstr="provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(db)
    '如果你的服务器采用较老版本access驱动,请用下面连接方法
    'connstr="driver={microsoft access driver (*.mdb)};dbq=" & server.mappath(db)
    conn.open connstr
    function closedatabase 
    conn.close
    set conn = nothing
    end function
    %>
    12.sql其他数据库 连接:
    <%
    option explicit
    dim startime,endtime,conn,connstr,db
    startime=timer()
    connstr="driver={sql server };server=hudenq-n11t33nb;uid=sa;pwd=xsfeihu;database =dvbbs" 
    set conn = server.createobject("adodb.connection")
    conn.open connstr
    function closedatabase 
    conn.close
    set conn = nothing
    end function
    %>
    13.用键盘打开网页代码:
    <script language="javascript">
    function ctlent(eventobject)
    {
    if((event.ctrlkey && window.event.keycode==13)||(event.altkey && window.event.keycode==83))
    {
    window.open('网址','','')
    }
    }
    </script>

    这里是ctrl+enter和alt+s的代码 自己查下键盘的ascii码再换就行!

    14.让层不被控件复盖代码:
    <div z-index:2><object xxx></object></div> # 前面 
    <div z-index:1><object xxx></object></div> # 后面 
    <div id="layer2" style="position:absolute; top:40;400px; height:95px;z-

    index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%

    ></td></tr></table><iframe width=0 height=0></iframe></div>
    <div id="layer1" style="position:absolute; top:50;200px; height:115px;z-

    index:1"><iframe height=100% width=100%></iframe></div>
    15.动网flash广告 代码:
    <object classid="clsid27cdb6e-ae6d-11cf-96b8-444553540000"

    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0

    ,0" width="468" height="60"><param name=movie value="images/yj16d.swf"><param name=quality

    value=high><embed src="images/dvbanner.swf" quality=high

    pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?

    p1_prod_version=shockwaveflash"; type="application/x-shockwave-flash" width="468"

    height="60"></embed></object>
    16.vbs弹出窗口小代码:
    <script language=vbscript>
    msgbox"你还没有注册或登陆论坛","0","精品论坛"
    location.href = "login.asp"
    </script>
    16.使用fso修改文件特定内容的函数
    function fsochange(filename,target,string)
    dim objfso,objcountfile,filetempdata
    set objfso = server.createobject("scripting.filesystemobject")
    set objcountfile = objfso.opentextfile(server.mappath(filename),1,true)
    filetempdata = objcountfile.readall
    objcountfile.close
    filetempdata=replace(filetempdata,target,string)
    set objcountfile=objfso.createtextfile(server.mappath(filename),true)
    objcountfile.write filetempdata 
    objcountfile.close
    set objcountfile=nothing
    set objfso = nothing
    end function
    17.使用fso读取文件内容的函数
    function fsofileread(filename)
    dim objfso,objcountfile,filetempdata
    set objfso = server.createobject("scripting.filesystemobject")
    set objcountfile = objfso.opentextfile(server.mappath(filename),1,true)
    fsofileread = objcountfile.readall
    objcountfile.close
    set objcountfile=nothing
    set objfso = nothing
    end function
    18.使用fso读取文件某一行的函数
    function fsolinedit(filename,linenum)
    if linenum < 1 then exit function
    dim fso,f,temparray,tempcnt
    set fso = server.createobject("scripting.filesystemobject")
    if not fso.fileexists(server.mappath(filename)) then exit function
    set f = fso.opentextfile(server.mappath(filename),1)
    if not f.atendofstream then
    tempcnt = f.readall
    f.close
    set f = nothing
    temparray = split(tempcnt,chr(13)&chr(10))
    if linenum>ubound(temparray)+1 then
    exit function
    else
    fsolinedit = temparray(linenum-1)
    end if
    end if
    end function
    19.使用fso写文件某一行的函数
    function fsolinewrite(filename,linenum,linecontent)
    if linenum < 1 then exit function
    dim fso,f,temparray,tempcnt
    set fso = server.createobject("scripting.filesystemobject")
    if not fso.fileexists(server.mappath(filename)) then exit function
    set f = fso.opentextfile(server.mappath(filename),1)
    if not f.atendofstream then
    tempcnt = f.readall
    f.close
    temparray = split(tempcnt,chr(13)&chr(10))
    if linenum>ubound(temparray)+1 then
    exit function
    else
    temparray(linenum-1) = linecontent
    end if
    tempcnt = join(temparray,chr(13)&chr(10))
    set f = fso.createtextfile(server.mappath(filename),true)
    f.write tempcnt
    end if
    f.close
    set f = nothing
    end function
    20.使用fso添加文件新行的函数
    function fsoappline(filename,linecontent)
    dim fso,f
    set fso = server.createobject("scripting.filesystemobject")
    if not fso.fileexists(server.mappath(filename)) then exit function
    set f = fso.opentextfile(server.mappath(filename),8,1)
    f.write chr(13)&chr(10)&linecontent
    f.close
    set f = nothing
    end function
    21.读文件最后一行的函数
    function fsolastline(filename)
    dim fso,f,temparray,tempcnt
    set fso = server.createobject("scripting.filesystemobject")
    if not fso.fileexists(server.mappath(filename)) then exit function
    set f = fso.opentextfile(server.mappath(filename),1)
    if not f.atendofstream then
    tempcnt = f.readall
    f.close
    set f = nothing
    temparray = split(tempcnt,chr(13)&chr(10))
    fsolastline = temparray(ubound(temparray))
    end if
    end function 




    servervariables 集合检索预定的环境变量。

    语法 
    request.servervariables (server environment variable)

    参数 
    服务器环境变量 
    指定要

     

    此文来自: 马开东博客 转载请注明出处 网址: http://www.makaidong.com

    检索的服务器环境变量名。可以使用下面列出的值。变量 说明 
    all_http 客户端发送的所有 http 标题文件。 
    all_raw 检索未处理表格中所有的标题。all_raw 和 all_http 不同,all_http 在标题文件名前面放置 http_ prefix,并且标题名称总是大写的。使用 all_raw 时,标题名称和值只在客户端发送时才出现。 
    appl_md_path 检索 isapi dll 的 (wam) application 的元其他数据库 路径。 
    appl_physical_path 检索与元其他数据库 路径相应的物理路径。iis 通过将 appl_md_path 转换为物理(目录)路径以返回值。 
    auth_password 该值输入到客户端的鉴定对话中。只有使用基本鉴定时,该变量才可用。 
    auth_type 这是用户访问受保护的脚本时,服务器用于检验用户的验证方法。 
    auth_user 未被鉴定的用户名。 
    cert_cookie 客户端验证的唯一 id,以字符串方式返回。可作为整个客户端验证的签字。 
    cert_flags 如有客户端验证,则 bit0 为 1。 
    如果客户端验证的验证人无效(不在服务器承认的 ca 列表中),bit1 被设置为 1。

    cert_issuer 用户验证中的颁布者字段(o=ms,ou=ias,cn=user name,c=usa)。 
    cert_keysize 安全套接字层连接关键字的位数,如 128。 
    cert_secretkeysize 服务器验证私人关键字的位数。如 1024。 
    cert_serialnumber 用户验证的序列号字段。 
    cert_server_issuer 服务器验证的颁发者字段。 
    cert_server_subject 服务器验证的主字段。 
    cert_subject 客户端验证的主字段。 
    content_length 客户端发出内容的长度。 
    content_type 内容的数据类型。同附加信息的查询一起使用,如 http 查询 get、 post 和 put。 
    gateway_interface 服务器使用的 cgi 规格的修订。格式为 cgi/revision。 
    http_<headername> headername 存储在标题文件中的值。未列入该表的标题文件必须以 http_ 作为前缀,以使 servervariables 集合检索其值。 
    注意 服务器将 headername 中的下划线(_)解释为实际标题中的破折号。例如,如果您指定 http_my_header,服务器将搜索以 my-header 为名发送的标题文件。

    https 如果请求穿过安全通道(ssl),则返回 on。如果请求来自非安全通道,则返回 off。 
    https_keysize 安全套接字层连接关键字的位数,如 128。 
    https_secretkeysize 服务器验证私人关键字的位数。如 1024。 
    https_server_issuer 服务器验证的颁发者字段。 
    https_server_subject 服务器验证的主字段。 
    instance_id 文本格式 iis 实例的 id。如果实例 id 为 1,则以字符形式出现。使用该变量可以检索请求所属的(元其他数据库 中)web 服务器实例的 id。 
    instance_meta_path 响应请求的 iis 实例的元其他数据库 路径。 
    local_addr 返回接受请求的服务器地址。如果在绑定多个 ip 地址的多宿主机器上查找请求所使用的地址时,这条变量非常重要。 
    logon_user 用户登录 windows nt&reg; 的帐号。 
    path_info 客户端提供的额外路径信息。可以使用这些虚拟路径和 path_info 服务器变量访问脚本。如果该信息来自 url,在到达 cgi 脚本前就已经由服务器解码了。 
    path_translated path_info 转换后的版本,该变量获取路径并进行必要的由虚拟至物理的映射。 
    query_string 查询 http 请求中问号(?)后的信息。 
    remote_addr 发出请求的远程主机的 ip 地址。 
    remote_host 发出请求的主机名称。如果服务器无此信息,它将设置为空的 mote_addr 变量。 
    remote_user 用户发送的未映射的用户名字符串。该名称是用户实际发送的名称,与服务器上验证过滤器修改过后的名称相对。 
    request_method 该方法用于提出请求。相当于用于 http 的 get、head、post 等等。 
    script_name 执行脚本的虚拟路径。用于自引用的 url。 
    server_name 出现在自引用 ual 中的服务器主机名、dns 化名或 ip 地址。 
    server_port 发送请求的端口号。 
    server_port_secure 包含 0 或 1 的字符串。如果安全端口处理了请求,则为 1,否则为 0。 
    server_protocol 请求信息协议的名称和修订。格式为 protocol/revision 。 
    server_software 应答请求并运行网关的服务器软件其他 的名称和版本。格式为 name/version 。 
    url 提供 url 的基本部分。


    注释 
    如果客户端发送的标题文件在上述表格中找不到,可以在调用 request.servervariables 中给标题文件名加上 http_ 的前缀以检索其值。例如,如果客户端发送标题文件

    somenewheader:somenewvalue

    您可以通过使用下面的语法检索 somenewvalue

    <% request.servervariables("http_somenewheader") %>

    您可使用重述符以循环遍历所有的服务器变量名。例如,使用下面的脚本打印出所有的服务器名。

    <table> 
    <tr><td><b>server variable</b></td><td><b>value</b></td></tr> 
    <% for each name in request.servervariables %> 
    <tr><td> <%= name %> </td><td> <%= request.servervariables(name) %> </td></tr> 
    </table> 
    <% next %>

    示例 
    下面的例子使用 request 对象显示一些服务器变量。

    <html> 
    <!-- this example displays the content of several servervariables. --> 
    all_http server variable = 
    <%= request.servervariables("all_http") %> <br> 
    content_length server variable = 
    <%= request.servervariables("content_length") %> <br> 
    content_type server variable = 
    <%= request.servervariables("content_type") %> <br> 
    query_string server variable = 
    <%= request.servervariables("query_string") %> <br> 
    server_software server variable = 
    <%= request.servervariables("server_software") %> <br> 
    </html>

    下一个示例使用 servervariables 集合将服务器名插入一个超文本链接。

    <a href = "http://<%= request.servervariables("server_name") %> 
    /scripts/mypage.asp">link to mypage.asp</a> 


    窗口在设定的时间内关闭 
    <script language="javascript">
    <!--
    function a(){
    window.opener=null;
    window.close();
    }
    settimeout("a()",6000);
    //-->
    </script>

    首页 图片消失
    <script language="javascript">
    function kick()
    {
    if(div1.style.pixeltop>-140)
    div1.style.pixeltop=div1.style.pixeltop-1
    }

    function kiss()
    {
    var p=setinterval("kick()",30);
    }

    function on_it()
    {
    div1.style.pixeltop=0;
    div1.style.pixeltop=0;
    }
    </script>

    <body onload="kiss()"  style="margin:0;0;0;0 ">
    <div style="top:0px; left:0px; position:absolute; background:red; 531px; height:120; z-index: 0;" id="div1"  onmouseover="on_it()"><img src="aa.jpg" width="179" height="146"><img src="dd.jpg" width="176" height="146"><img src="ff.jpg" width="175" height="146"></div>

    </body>

    自动提交
    <body id="b"> <form action="arr.asp" method="post"  name="form1">   <input type="text" name="textfield" value="454">   <input type="submit" name="submit" value="提交"> </form> <script language="javascript" type="text/javascript"> function b.onload() { document.form1.submit(); } </script> </body>  
    自动提交 ok

    <body onload="go_time()"> <form name="form1" method="post" action="news.html">  <input type="hidden" name="textfield">  <input type="hidden" name="textfield2"> </form> <script language="javascript" type="text/javascript"> function go_it() { document.form1.submit(); } // function go_time() { var p=settimeout("go_it()",3000); }  </script> 

  • 相关阅读:
    java web 入门实例servlet篇(显示后台数据库列表,删除某一条记录并显示)
    我的成长比价系列:java web开发过程中遇到的错误一:sql语句换行错误
    spring mvc + velocity 搭建实例程序maven版本并且使用的是tomcat容器而不是jetty(step by step)
    spring mvc学习笔记(一)web.xml文件配置的一点重要信息
    与数据库连接的页面增删改查 的easyui实现(主要是前端实现)
    oracle 11g 空表导出
    EMCA和EMCTL的简单用法
    vs2010补丁
    CAS 策略已被 .NET Framework 弃用
    sqlserver2008 链接服务器 2000
  • 原文地址:https://www.cnblogs.com/ince/p/9156652.html
Copyright © 2020-2023  润新知