linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘建议留言网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > ASP >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·由HTTP 500 Internal server e
·会员系统“找回密码”的制作方
·简单的asp验证码程序示例
·ASP实现数字和字母组合并生成图
·如何用foreach遍历页面上所有的
·用ASP制作强大的搜索引擎
·如何让图片自动缩放以适合界面
·如何实现站点的RSS输出
·采用XMLHTTP编写一个天气预报的
·ASP如何获取真实IP地址
·无组件实现文件上传/下载
·asp中如何调试 ASP 脚本
·asp+ajax打造无刷新新闻评论系
·典型Datagrid分页、排序、删除
·asp中如何使用 HTML 表格
最新文章
·ASP教程:8、ASP内建对象Respo
·ASP教程:7、ASP内建对象Reque
·ASP教程:6、ASP脚本循环语句
·ASP教程:5、ASP脚本变量、函数
·ASP教程:4、ASP脚本基础
·ASP教程:3、ASP基础
·ASP教程:2、ASP简介
·ASP教程:1、Are you ready?
·ASP中使用SQL语句教程
·ASP进度条
·由HTTP 500 Internal server e
·Asp无组件生成缩略图
·ASP 系列函数大全(4)
·ASP 系列函数大全(3)
·ASP 系列函数大全(2)
Google
 
asp的19个基本技巧
[ 作者:  加入时间:2007-10-09 11:11:37  来自:Linux联盟收集整理 ]
1. 现在的日期时间命令是 z5RLinux联盟
<%=now%> 即可 z5RLinux联盟
z5RLinux联盟
2.ASP取得表格(from)数据输入的方法,是使用一个内置的对象(object)—Requect, z5RLinux联盟
它以get,post而异。 z5RLinux联盟
z5RLinux联盟
3.若要自己用VB或其它语言编写,.dll文件供ASP使用需将DLL文件注册方可:DOS下 z5RLinux联盟
输入 regsbr32 *.dll z5RLinux联盟
z5RLinux联盟
4.显示五个重复的句子,字体越来越大 z5RLinux联盟
<% for i=1 to 5 %> z5RLinux联盟
<font size=<% =i %> color=#00ffff> z5RLinux联盟
快速ASP z5RLinux联盟
</font> z5RLinux联盟
<br> z5RLinux联盟
<% next %> z5RLinux联盟
z5RLinux联盟
5.传送字符串到用户端 z5RLinux联盟
response.write string z5RLinux联盟
如:<% response.write "Welcome" %> z5RLinux联盟
z5RLinux联盟
6.链接到指定的URL地址 z5RLinux联盟
response.redirect url z5RLinux联盟
如: z5RLinux联盟
<% response.redirect "homepage.asp" z5RLinux联盟
%> z5RLinux联盟
z5RLinux联盟
*但是如果此.ASP的文件内容已经传送到用户断,则再用redirect时会发生错误。 z5RLinux联盟
z5RLinux联盟
7.其他语言与ASP的结合: z5RLinux联盟
如:早上显示早安,下午显示你好 z5RLinux联盟
<% z5RLinux联盟
if time>+#12:00:00 AM# and time<#12:00:00 PM # z5RLinux联盟
then z5RLinux联盟
greeting="早安!" z5RLinux联盟
else z5RLinux联盟
greeting="你好!" z5RLinux联盟
end if z5RLinux联盟
%> z5RLinux联盟
<%=greeting %> z5RLinux联盟
z5RLinux联盟
8.<script>标记在ASP中的应用 z5RLinux联盟
例: z5RLinux联盟
z5RLinux联盟
<html> z5RLinux联盟
<body> z5RLinux联盟
<% call function1 %> z5RLinux联盟
</body> z5RLinux联盟
</html> z5RLinux联盟
<script runat=server language=javascript> z5RLinux联盟
function function1() z5RLinux联盟
{ z5RLinux联盟
... z5RLinux联盟
} z5RLinux联盟
</script> z5RLinux联盟
z5RLinux联盟
9.#include 包括其它文件 z5RLinux联盟
<!--#include virtual|file="filename"--> z5RLinux联盟
virtual指虚拟的文件地址。 z5RLinux联盟
file 代表绝对的文件地址。 z5RLinux联盟
如: z5RLinux联盟
<!--#include virtual="/booksamp/test.asp"--> z5RLinux联盟
<!--#include file="/test/test.asp"--> z5RLinux联盟
z5RLinux联盟
而且可以层层嵌套。另外#include 不能在<%--%>之内 z5RLinux联盟
z5RLinux联盟
10.ASP取得表格输入数据的方法 z5RLinux联盟
:GET POST z5RLinux联盟
一.get:用户端将数据加到URL后,格式为”?字段1=输入数据1&字段2=输入数据2&...", z5RLinux联盟
再将其送到服务器。 z5RLinux联盟
如: action为www.abc.com, 字段Name输入数据为jack,字段age的数据为15,则用get方法为 z5RLinux联盟
http://www.abc.com?Name=jack&Age=15 z5RLinux联盟
z5RLinux联盟
二.post:用户端用http信息数据传送到服务器 z5RLinux联盟
ASP中: z5RLinux联盟
get:使用“输入数据= Request.QueryString("字段名")",将附加于URL的数据取出。 z5RLinux联盟
post:使用“输入数据=Request.Forml"(字段名")",读取HTTP信息数据字段。 z5RLinux联盟
* Request.QueryString范例 z5RLinux联盟
如:〈A hery="aspform.asp?Name=jack&Age=15"> z5RLinux联盟
按此〈/A〉〈p〉 z5RLinux联盟
Name:<%=request.QueryString("Name")%) z5RLinux联盟
Age:<%=request.QeueryString("Age")%) z5RLinux联盟
* get 范例 z5RLinux联盟
·aspturm.asp: z5RLinux联盟
<form action="asp1b.asp" method="get"> z5RLinux联盟
姓名: <input type=text name="input1" value="Your name"> z5RLinux联盟
<p> z5RLinux联盟
特征: <select name="input2"> z5RLinux联盟
<option>cool! z5RLinux联盟
<option>handsome z5RLinux联盟
<option>warmhearted z5RLinux联盟
</select> z5RLinux联盟
<input type=submit value="ok"> z5RLinux联盟
</form> z5RLinux联盟
asp1b.asp的内容 z5RLinux联盟
<html><body> z5RLinux联盟
<% =request.querystring("input1") %> hi, your character is z5RLinux联盟
<%= request.querystring("input2") %> z5RLinux联盟
</body></html> z5RLinux联盟
11.request.From z5RLinux联盟
语法: request.From(name)[(index)|.count] z5RLinux联盟
name:字段名 z5RLinux联盟
index:当同一字段输入多个值时,指针值index指定要读取同一字段的那一个值,范围由1到 z5RLinux联盟
request.From(name).count z5RLinux联盟
count:由request.From(name).count可知name字段输入几个值,若无此name字段,count为0 z5RLinux联盟
z5RLinux联盟
z5RLinux联盟
如下例: z5RLinux联盟
<% z5RLinux联盟
forI=1 to request.fron("input1").count z5RLinux联盟
response.write request.From("input1")(I)&"<br>" z5RLinux联盟
next z5RLinux联盟
%> z5RLinux联盟
若input1有两个值则都显示出 z5RLinux联盟
*若未采用index指定读取哪个.可用 z5RLinux联盟
〈% z5RLinux联盟
for each item request.From("input")) z5RLinux联盟
repomse.write item &"<br>" z5RLinux联盟
next z5RLinux联盟
%> z5RLinux联盟
也可用" for each x in tewuest.From"重复取得所有字段的输入值。 z5RLinux联盟
z5RLinux联盟
<% for each x in request.Form %> z5RLinux联盟
request.From (<%=x%)=<%=request.Form z5RLinux联盟
(x)%> <br> z5RLinux联盟
<% next %> z5RLinux联盟
z5RLinux联盟
z5RLinux联盟
12. z5RLinux联盟
获取客户端TCP/IP端口的方法: z5RLinux联盟
如: tcp/ip port is <%=request("server_port")%> z5RLinux联盟
使用server_port可以得到接收HTTP request的连接port信息 z5RLinux联盟
z5RLinux联盟
z5RLinux联盟
13. z5RLinux联盟
通过HTTP_ACCEPT_LANGUAGE的HTTP表头信息,可以得到用户端的使用语言 z5RLinux联盟
环境. z5RLinux联盟
以下例子判断用户端的语言环境,给出不同的页面. z5RLinux联盟
<% language=request.servervariables("HTTP_ACCEPT_LANGUAGE") z5RLinux联盟
if language="en" then %> z5RLinux联盟
<!--#include file="english.asp"> z5RLinux联盟
<% else %> z5RLinux联盟
<!--#include file="china.asp"> z5RLinux联盟
<% end if%> z5RLinux联盟
z5RLinux联盟
14.主页保留的期限 z5RLinux联盟
如果用户端浏览器在一个主页保留的期限内,再度浏览此主页,则原在用 z5RLinux联盟
户端硬盘上的主页内容将被显示. z5RLinux联盟
response.expires[=number] z5RLinux联盟
其中NUMBER为记录数据盒(PAGE BOX)的保留期限,单位是分钟. z5RLinux联盟
或: z5RLinux联盟
response.expiresabsolute[=[date][time]] z5RLinux联盟
如:设定一个主页保留期到某个日子. z5RLinux联盟
z5RLinux联盟
15.连接到指定的URL地址 z5RLinux联盟
如:你希望确认用户已经看过INDEX.HTM,则可以检查是否已经看过,如 z5RLinux联盟
尚未确认,则自动连接到首页 z5RLinux联盟
<% z5RLinux联盟
if not session("BEEN_to_home_page") then z5RLinux联盟
response.redirect "index.asp" z5RLinux联盟
end if z5RLinux联盟
%> z5RLinux联盟
z5RLinux联盟
16.判断是回到本页还是第一次进入 z5RLinux联盟
<% z5RLinux联盟
if user_has_been_here_before then z5RLinux联盟
response.write "<h3 align=center> Welcome Back z5RLinux联盟
again" z5RLinux联盟
else z5RLinux联盟
response.write "Welcome!" z5RLinux联盟
end if z5RLinux联盟
%> z5RLinux联盟
z5RLinux联盟
z5RLinux联盟
17.显示数据库中的图片与超级连接 z5RLinux联盟
z5RLinux联盟
<% z5RLinux联盟
set conn=server.creatobject("ADODB.connection") z5RLinux联盟
conn.open "myaddress" z5RLinux联盟
set rs=conn.execute("select name,tel,url,image from z5RLinux联盟
myaddress") z5RLinux联盟
%> z5RLinux联盟
z5RLinux联盟
<p> z5RLinux联盟
<tabel> z5RLinux联盟
<tr> z5RLinux联盟
<% for i=0 to rs.fields.count-1 %> z5RLinux联盟
<td> z5RLinux联盟
<b> z5RLinux联盟
<%=rs(i).name %> z5RLinux联盟
</b> z5RLinux联盟
</td> z5RLinux联盟
<% next %> z5RLinux联盟
</tr> z5RLinux联盟
<% do while not rs.eof %> z5RLinux联盟
<tr> z5RLinux联盟
<% for i=0 to rs.fields.count-1 %> z5RLinux联盟
<td valign =top> z5RLinux联盟
<% z5RLinux联盟
if rs(i).name="image" then z5RLinux联盟
response.write "<img src="""&rs(i)&""" >" z5RLinux联盟
else z5RLinux联盟
if rs(i).name="url" then z5RLinux联盟
response.write "<a href="""&rs(i)&""">"&rs(i)&"</a>" z5RLinux联盟
else z5RLinux联盟
response.write rs(i) z5RLinux联盟
end if z5RLinux联盟
end if z5RLinux联盟
%> z5RLinux联盟
</td> z5RLinux联盟
<%next%> z5RLinux联盟
</tr> z5RLinux联盟
<% rs.movenext z5RLinux联盟
loop z5RLinux联盟
rs.close z5RLinux联盟
conn.close z5RLinux联盟
%> z5RLinux联盟
</html> z5RLinux联盟
z5RLinux联盟
z5RLinux联盟
18. 用ASP取得浏览器信息 z5RLinux联盟
<% z5RLinux联盟
set a=server.creatobject("MSWC.BROWSERTYPE") z5RLinux联盟
msg="您使用的浏览器是:"+a.browser+"version"+a.version z5RLinux联盟
%> z5RLinux联盟
<%=msg%> z5RLinux联盟
z5RLinux联盟
z5RLinux联盟
19. asp访问cookies的方式(使用response和request) z5RLinux联盟
如下: z5RLinux联盟
写入cookies: z5RLinux联盟
response.cookies("待写入的coookies名称") z5RLinux联盟
="待写入数据“ z5RLinux联盟
读取cookies: z5RLinux联盟
读取数据=request.cookies("待读的cookies名称") z5RLinux联盟
z5RLinux联盟
* 写入时注意 z5RLinux联盟
@ 写入cookies的response.cookies程序段必须放在<html>标记 z5RLinux联盟
之前。而且不可以有任何的其他html代码 z5RLinux联盟
@ COOKIES中必须使用expires设定有效期, COOKIES才能真正的 z5RLinux联盟
写入客户端硬盘中。如: z5RLinux联盟
response.cookies("待写入的名称“).expires=#july 1,1998# z5RLinux联盟
或response.cookies("名称").expires=DATE+365 Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·DELPHI中操作ACCESS技巧集  (2007-10-30 16:08:48)
 ·Delphi中树型控件的使用技巧  (2007-10-30 15:41:50)
 ·Javascript+ASP打造无刷新新闻列表  (2007-10-30 14:23:38)
 ·网页实用技巧:随机显示不同页面背景  (2007-10-30 13:55:09)
 ·内存调试技巧:C 语言最大难点揭秘  (2007-10-30 13:45:40)
 ·如何将asp.net的后台cs代码移动到页面上  (2007-10-29 14:25:45)
 ·读Programming ASP.NET中文版控件  (2007-10-29 14:15:23)
 ·ASP.NET 2.0如何封装JS和CSS文件为服务器端控件  (2007-10-29 14:13:11)
 ·大数据量填充UI的技巧  (2007-10-29 14:12:33)
 ·asp.net中用VML动态的画出数据分析图表详解  (2007-10-29 14:07:23)