ASP编程中18个基本技巧

时间:2008-08-08 07:15:34  类别:ASP  作者:蝶舞未来

1. 现在的日期时间命令是<%=now%> 即可
    
    2.ASP取得表格(from)数据输入的方法,是使用一个内置的对象(object)—Requect,它以get,post而异。
    
    3.若要自己用VB或其它语言编写,.dll文件供ASP使用需将DLL文件注册方可:DOS下输入 regsbr32 *.dll
    
    4.显示五个重复的句子,字体越来越大
    <% for i=1 to 5 %>
    <font size=<% =i %> color=#00ffff>
    ALLASP
    </font>
    <br>
    <% next %>
    
    5.传送字符串到用户端
    response.write string
    如:<% response.write "Welcome" %>
    
    6.链接到指定的URL地址
    response.redirect url
    如:
    <% response.redirect "homepage.asp"
    %>
    
    *但是如果此.ASP的文件内容已经传送到用户断,则再用redirect时会发生错误。
    
    7.其他语言与ASP的结合:
    如:早上显示早安,下午显示你好
    <%
    if time>+#12:00:00 AM# and time<#12:00:00 PM #
    then
    greeting="早安!"
    else
    greeting="你好!"
    end if
    %>
    <%=greeting %>
    
    8.<script>标记在ASP中的应用
    例:
    
    <html>
    <body>
    <% call function1 %>
    </body>
    </html>
    <script runat=server language=javascript>
    function function1()
    {
    ...
    }
    </script>
    
    9.#include 包括其它文件
    <!--#include virtual|file="filename"-->
    virtual指虚拟的文件地址。
    file 代表绝对的文件地址。
    如:
    <!--#include virtual="/booksamp/test.asp"-->
    <!--#include file="/test/test.asp"-->
    
    而且可以层层嵌套。另外#include 不能在<%--%>之内
    
    10.ASP取得表格输入数据的方法
    :GET POST
    一.get:用户端将数据加到URL后,格式为”?字段1=输入数据1&字段2=输入数据2&...",
    再将其送到服务器。
    如: action为www.abc.com, 字段Name输入数据为jack,字段age的数据为15,则用get方法为
    http://www.abc.com?Name=jack&Age=15
    
    二.post:用户端用http信息数据传送到服务器
    ASP中:
    get:使用“输入数据= Request.QueryString("字段名")",将附加于URL的数据取出。
    post:使用“输入数据=Request.Forml"(字段名")",读取HTTP信息数据字段。
    * Request.QueryString范例
    如:〈A hery="aspform.asp?Name=jack&Age=15">
    按此〈/A〉〈p〉
    Name:<%=request.QueryString("Name")%)
    Age:<%=request.QeueryString("Age")%)
    * get 范例
    ·aspturm.asp:
    <form action="asp1b.asp" method="get">
    姓名: <input type=text name="input1" value="Your name">
    <p>
    特征: <select name="input2">
    <option>cool!
    <option>handsome
    <option>warmhearted
    </select>
    <input type=submit value="ok">
    </form>
    asp1b.asp的内容
    <html><body>
    <% =request.querystring("input1") %> hi, your character is
    <%= request.querystring("input2") %>
    </body></html>
    11.request.From
    语法: request.From(name)[(index)|.count]
    name:字段名
    index:当同一字段输入多个值时,指针值index指定要读取同一字段的那一个值,范围由1到
    request.From(name).count
    count:由request.From(name).count可知name字段输入几个值,若无此name字段,count为0
    
    
    如下例:
    <%
    forI=1 to request.fron("input1").count
    response.write request.From("input1")(I)&"<br>"
    next
    %>
    若input1有两个值则都显示出
    *若未采用index指定读取哪个.可用
    〈%
    for each item request.From("input"))
    repomse.write item &"<br>"
    next
    %>
    也可用" for each x in tewuest.From"重复取得所有字段的输入值。
    
    <% for each x in request.Form %>
    request.From (<%=x%)=<%=request.Form
    (x)%> <br>
    <% next %>

 


特别推荐

广而告之