asp下最常用的19個基本技巧第1/2頁

來源:互聯網
上載者:User

asp的19個基本技巧
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>
快速ASP
</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 %>

12.
擷取用戶端TCP/IP連接埠的方法:
如: tcp/ip port is <%=request("server_port")%>
使用server_port可以得到接收HTTP request的串連port資訊

13.
通過HTTP_ACCEPT_LANGUAGE的HTTP表頭資訊,可以得到使用者端的使用語言
環境.
以下例子判斷使用者端的語言環境,給出不同的頁面.
<% language=request.servervariables("HTTP_ACCEPT_LANGUAGE")
if language="en" then %>
<!--#include file="english.asp">
<% else %>
<!--#include file="china.asp">
<% end if%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.