ASP内置对象之Request对象

来源:互联网 发布:python频域转时域 编辑:程序博客网 时间:2024/05/20 06:39

一、功能:浏览器向服务器发出请求,即接受从客户端传来的数据
 
二、集合(Collection)
Request对象把客户端信息保存在几个集合中,供ASP应用使用。
使用格式:Request.Collection("membername")

常用的集合有:
1.QueryString集合

当HTML表单中的method="get"时,可以用Request.QueryString来获取表单提交的信息
格式:Request.QueryString(Varible)[(Index).Count]

注:
1>QueryString集合是查询字符串的所有值的集合。
2>Varible是在查询字符串某一变量的名称。
3>当某一变量具有多于一个值时,使用Index。
4>当某一参数具有多值时,Count指明值的个数。

例:fillinfo_get.html
------------------------------------fillinfo_get.html-----------------------------
<html>
<head>
  <title>QueryString接受HTML表单使用get方法传递的数据</title>
</head>
<body>
  <font color="#0000ff" >请填写如下信息:</font><br>
  <div align="center">
      <form name="info" action="showinfo_get.asp" method="get">
      姓名:<input type="text" name="name" size=19><br>
      密码:<input type="password" name="pwd"><br>
      <input type="submit" name="ok" value="确定">
      <input type="reset"  name="reset" value="重置"><br>
  </form>
  </div>
</body>
</html>
------------------------------------fillinfo_get.html--------------------------------------


showinfo_get.asp:
------------------------------------showinfo_get.asp-------------------------------------
<% @ language="JavaScript" %>
<html>
<head>
  <title>显示信息</title>
</head>
<body>
  <%
     var myname=Request.QueryString("name"), //name为姓名文本框输入的内容
         mypwd =Request.QueryString("pwd");  //pwd 为密码框输入的的内容
     Response.Write("姓名:"+myname+"<br>"+"密码:"+mypwd+"<br>");
  %>
</body>
</html>
------------------------------------showinfo_get.asp-------------------------------------

2.Form集合
当HTML表单中method="post"时,可以用Request.Form来获取HTML表单提交的信息。
格式:Request.Form(Parameter)[(Index).Count]

注:
1>Request.Form获取的是一个集合(collection);

2>Request.Form 集合有个参数Parameter,对应HTML表单控件的name值;
格式:Request.Form(Parameter)
Parameter是在HTML表单中某一元素的名称

3.当某一参数具有不止一个值(比如,当在<SELECT>中使用MULTIPLE属性时)时,使用Index。
格式:Request.Form(Parameter)(index)
index 从1开始计数。

当某一参数具有多值时,Count指明多值的个数。
格式:Request.Form(Parameter).count

例:fillinfo_post.html
------------------------------------fillinfo_post.html-------------------------------------
<html>
<head>
  <title>method=post</title>
</head>
<body>
    <form name="chose" action="showinfo_post.asp" method="post">
      <h3>请选择你喜欢的港剧</h3>
      <input type="checkbox" name="gj" value="天龙八部">天龙八部<br>
      <input type="checkbox" name="gj" value="创世纪"  >创世纪<br>
      <input type="checkbox" name="gj" value="射雕英雄传">射雕英雄传<br>
      <input type="checkbox" name="gj" value="神雕侠侣">神雕侠侣<br>
      <input type="submit" name="ok" value="确定">
      <input type="reset" name="reset" value="重置"><br>
    </form>
</body>
</html>
------------------------------------fillinfo_post.html-------------------------------------
showinfo_post.asp
------------------------------------showinfo_post.asp-------------------------------------
<%@ language="JavaScript" %>
<html>
<head>
  <title>你最喜欢的港剧</title>
</head>
<body>
  <%
     Response.Write("你最喜欢的港剧有:<br>");
     var num=Request.Form("gj").count;
     Response.Write("你选中了"+num+"个:<br>");
     Response.Write("<p>"+Request.Form("gj")+"<br></p>");
    
     for(var index=1;index<=num;index++)
       {
          Response.Write(Request.Form("gj")(index)+"<br>");
       }
  %>
</body>
</html>
------------------------------------showinfo_post.asp-------------------------------------
3.ServerVariable集合

ServerVariables集合用于取回服务器变量的值。

语法:Request.ServerVariables(server_variable)
server_variable:要取回的服务器变量的名称。

例:testSV.asp
-----------------------------------------testSV.asp----------------------------------------
<% @language="JavaScript" %>
<html>
<head>
  <title>测试几个简单的Request.ServerVariables集合变量</title>
</head>
<body>
   <p><b>你的IP地址是:</b>
   <%
      var ip=Request.ServerVariables("REMOTE_ADDR");
      Response.Write(ip+"<br>");
   %>
   </p><hr>
   <p><b>你的主机名是:</b>
   <%
      var hostname=Request.ServerVariables("REMOTE_HOST");
      Response.Write(hostname+"<br>");
   %>
   </p><hr>

   <p><b>服务器主机名是:</b>
   <%
      var servername=Request.ServerVariables("SERVER_NAME");
      Response.Write(servername+"<br>");
   %>
   </p><hr>

   <p><b>服务器端口是:</b>
   <%
      var serverport=Request.ServerVariables("SERVER_PORT");
      Response.Write(serverport+"<br>");
   %>
   </p><hr>
<body>

</html>
-----------------------------------------testSV.asp----------------------------------------
4.Cookies
这个和后面的Response对象的Cookies一起学习

原创粉丝点击