request

JavaScript

JavaScript语言参考手册      技术交流 :迷途知返 pwwang.com
JavaScript手册
【目录】 【上一页】 【下一页】 【索引】

request

Contains data specific to the current client request.

服务器端对象
实现版本 LiveWire 1.0

创建源

The JavaScript runtime engine on the server automatically creates a request object for each client request.

描述

The JavaScript runtime engine on the server creates a request object each time the client makes a request of the server. The runtime engine destroys the request object after the server responds to the request, typically by providing the requested page.

The properties listed below are read-only properties that are initialized automatically when a request object is created. In addition to these predefined properties, you can create custom properties to store application-specific data about the current request.

属性概览

agent Provides name and version information about the client software.
imageX The horizontal position of the mouse pointer when the user clicked the mouse over an image map.
imageY The vertical position of the mouse pointer when the user clicked the mouse over an image map.
inputName Represents an input element on an HTML form. (There is not a 属性 whose name is inputName. Rather, each instance of request has properties named after each input element.)
ip Provides the IP address of the client.
方法 Provides the HTTP 方法 associated with the request.
protocol Provides the HTTP protocol level supported by the client's software.

方法概览

无。

示例

示例 1. This example displays the values of the predefined properties of the request object. In this example, an HTML form is defined as follows:

<FORM METHOD="post" NAME="idForm" ACTION="hello.html">
<P>Last name:
   <INPUT TYPE="text" NAME="lastName" SIZE="20">
<BR>First name:
   <INPUT TYPE="text" NAME="firstName" SIZE="20">
</FORM>
The following code displays the values of the request object properties that are created when the form is submitted:

agent = <SERVER>write(request.agent)</SERVER><BR>
ip = <SERVER>write(request.ip)</SERVER><BR>
method = <SERVER>write(request.method)</SERVER><BR>
protocol = <SERVER>write(request.protocol)</SERVER><BR>
lastName = <SERVER>write(request.lastName)</SERVER><BR>
firstName = <SERVER>write(request.firstName)</SERVER>
When it executes, this code displays information similar to the following:

agent = "Mozilla/2.0 (WinNT;I)"
ip = "165.327.114.147"
method = "GET"
protocol = "HTTP/1.0"
lastName = "Schaefer"
firstName = "Jesse"
示例 2. The following example creates the requestDate property and initializes it with the current date and time:

request.requestDate = new Date() 示例 3. When a user clicks the following link, the info.html page is loaded, request.accessedFrom is created and initialized to "hello.html", and request.formId is created and initialized to "047".

Click here for
<A HREF="info.html?accessedFrom=hello.html&formId=047">
additional information</A>.

参看

client, project, server

属性

Custom属性

You can create a property for the request object by assigning it a name and a value. For example, you can create a request property to store the date and time that a request is received so you can enter the date into the page content.

You can also create request object properties by encoding them in a URL. When a user navigates to the URL by clicking its link, the properties are created and instantiated to values that you specify. The properties are valid on the destination page.

Use the following语法 to encode a request property in a URL:

<A HREF="URL?propertyName=value&propertyName=value..."> where:

  • URL is the URL the page that will get the new request properties.
  • propertyName is the name of the property you are creating.
  • value is the initial value of the new property.
Use escape to encode non-alphanumeric values in the URL string.

You can also create custom properties for the request object.

agent

Provides name and version information about the client software.

属性源 request
只读
实现版本 LiveWire 1.0

描述

The agent property identifies the client software. Use this information to conditionally employ certain features in an application.

The value of the agent property is the same as the value of the userAgent property of the client-side navigator object. The agent property specifies client information in the following format:

codeName/releaseNumber (platform; country; platformIdentifier)

The values contained in this format are the following:

  • codeName is the code name of the client. For example, "Mozilla" specifies Navigator.
  • releaseNumber is the version number of the client. For example, "2.0b4" specifies Navigator 2.0, beta 4.
  • platform is the platform upon which the client is running. For example, "Win16" specifies a 16-bit version of Windows, such as Windows 3.11.
  • country is either "I" for the international release or "U" for the domestic U.S. release. The domestic release has a stronger encryption feature than the international release.
  • platformIdentifier is an optional identifier that further specifies the platform. For example, in Navigator 1.1, platform is "windows" and platformIdentifier is "32bit". In Navigator 2.0, both pieces of information are contained in the platform designation. For example, in Navigator 2.0, the previous platform is expressed as "WinNT".

示例

The following example displays client information for Navigator 2.0 on Windows NT:

write(request.agent)
\\Displays "Mozilla/2.0 (WinNT;I)"
The following example evaluates the request.agent property and runs the oldBrowser procedure for clients other than Navigator 2.0. If the browser is Navigator 2.0, the currentBrowser function executes.

<SERVER>
var agentVar=request.agent
if (agentVar.indexOf("2.0")==-1)
   oldBrowser()
else
   currentBrowser()
</SERVER>

参看

request.ip, request.method, request.protocol

imageX

The horizontal position of the mouse pointer when the user clicked the mouse over an image map.

属性源 request
只读
实现版本 LiveWire 1.0

描述

The ISMAP attribute of the IMG tag indicates a server-based image map. When the user clicks the mouse with the pointer over an image map, the horizontal and vertical position of the pointer are returned to the server.

The imageX property returns the horizontal position of the mouse cursor when the user clicks on an image map.

示例

Suppose you define the following image map:

<A HREF="mapchoice.html">
<IMG SRC="images\map.gif" WIDTH=599 WIDTH=424 BORDER=0 ISMAP
ALT="SANTA CRUZ COUNTY">
</A>
Note the ISMAP attribute that makes the image a clickable map. When the user clicks the mouse on the image, the page mapchoice.html will have properties request.imageX and request.imageY based on the mouse cursor position where the user clicked.

参看

request.imageY

imageY

The vertical position of the mouse pointer when the user clicked the mouse over an image map.

属性源 request
只读
实现版本 LiveWire 1.0

描述

The ISMAP attribute of the IMG tag indicates a server-based image map. When the user clicks the mouse with the pointer over an image map, the horizontal and vertical position of the pointer are returned to the server.

The imageY property returns the vertical position of the mouse cursor when the user clicks on an image map.

示例

See example for imageX.

参看

request.imageX

inputName

Represents an input element on an HTML form.

属性源 request
只读
实现版本 LiveWire 1.0

描述

Each input element in an HTML form corresponds to a property of the request object. The name of each of these properties is the name of the field on the associated form. inputName is a variable that represents the value of the name property of an input field on a submitted form. By default, the value of the JavaScript name property is the same as the HTML NAME attribute.

示例

The following HTML source creates the request.lastName and the request.firstName properties when idForm is submitted:

<FORM METHOD="post" NAME="idForm" ACTION="hello.html">
<P>Last name:
   <INPUT TYPE="text" NAME="lastName" SIZE="20">
<BR>First name:
   <INPUT TYPE="text" NAME="firstName" SIZE="20">
</FORM>

ip

Provides the IP address of the client.

属性源 request
只读
实现版本 LiveWire 1.0

描述

The IP address is a set of four numbers between 0 and 255, for example, 198.217.226.34. You can use the IP address to authorize or record access in certain situations.

示例

In the following example, the indexOf method evaluates request.ip to determine if it begins with the string "198.217.226". The if statement executes a different function depending on the result of the indexOf method.

<SERVER>
var ipAddress=request.ip
if (ipAddress.indexOf("198.217.226.")==-1)
   limitedAccess()
else
   fullAccess()
</SERVER>

参看

request.agent, request.method, request.protocol

method

Provides the HTTP method associated with the request.

属性源 request
只读
实现版本 LiveWire 1.0

描述

The value of the method property is the same as the value of the method property of the client-side Form object. That is, method reflects the METHOD attribute of the FORM tag. For HTTP 1.0, the method property evaluates to either "get" or "post". Use the method property to determine the proper response to a request.

示例

The following example executes the postResponse function if the method property evaluates to "post". If method evaluates to anything else, it executes the getResponse function.

<SERVER>
if (request.method=="post")
   postResponse()
else
   getResponse()
</SERVER>

参看

request.agent, request.ip, request.protocol

protocol

Provides the HTTP protocol level supported by the client's software.

属性源 request
只读
实现版本 LiveWire 1.0

描述

For HTTP 1.0, the protocol value is "HTTP/1.0". Use the protocol property to determine the proper response to a request.

示例

In the following example, the currentProtocol function executes if request.protocol evaluates to "HTTP/1.0".

<SERVER>
if (request.protocol=="HTTP/1.0"
   currentProtocol()
else
   unknownProtocol()
</SERVER>

参看

request.agent, request.ip, request.method


【目录】 【上一页】 【下一页】 【索引】

返回页面顶部