When using dynamic web page technology to create ASP applications, you usually have at least two or more Web pages. At this time, you have to consider the processing of transferring data between multiple Web pages. Each page of an ASP application is similar to the form form of a Windows application. Data transfer between forms of a Windows application can be achieved by defining global variables and other methods. There are many different ways to transfer data between web pages, and the appropriate selection of data transfer methods between web pages plays a decisive role in the rationality and security of system design and operation.
1. URL method
The URL method is the most basic method to realize data transfer between Web. It is simple to operate and can easily realize data transfer between different Web pages, but its security is relatively poor. The data to be transferred is appended to the web page address (URL) and passed. Such as: http://www.downcodes.com/testweb?username=liming , where? The string that follows is the passed data. The variable name is before =, and the value is after =. You can use the request object to obtain the passed data. Such as: request("username"). In this method, the data content is displayed in the URL bar during the data transmission process, and the user can see the submitted content.
2. The form method
creates a form interaction area on the web page. The user inputs data on the browser and then submits it to the server through the form. The corresponding data can be received in the page that accepts the form data after submission, that is, the action page of the form. The request object can be used to receive the passed data.
For example:
Send page:
<form name="formtest" action="targetweb.asp">
<input name="testtext" type="text" value="">
<input name="testbutton" type="submit" value="submit">
</form>
Receiving page: request ("testtext")
uses the text box of the form page to receive input of user data. After submitting through the submit button, request is used in the target web page to receive the data.
3. Cookie method
Cookies are small files written by the web server on the browser side when browsing the page. Cookies are stored on the local disk of the browser, not on the server side. You can write cookies when sending data and read cookies when receiving to complete the transfer of data between Web pages.
For example:
sending page: response.cookies("cookiename")("username") = "liming"
receiving page: request.cookie("cookiename")("username")
assign a value to the cookie variable in the sending page, and in the receiving page The value of the cookie variable is the data passed.
4. Application object
The application object is used to record information about the entire website. It records variables shared by different browsers. No matter how many viewers access the web page at the same time, only one application object instance will be generated. Users can realize data transfer between web pages by defining application-wide shared variables. The definition method is: application ("variable name") = numerical value.
For example: application ("usrname") =liming.
The variables defined by the application object are visible to all browsers, so their usage is global and shared by all browsers. Data transfer.
5. Session object
The session object is used to record variables on the browser side. It is a variable dedicated to individual browsers. A session object will be automatically generated for each browser access. This object provides a storage place to store only the Variables and objects available to web pages opened by this visitor during the active period of the session. This can be used to pass data across the Web that is intended for use by a single browser. Its definition method: session ("variable name") = numerical value
such as: session ("usename") =liming
The variables defined by the session object are only dedicated variables on the browser side, so they are suitable for web page data transfer between local sessions.
6. Conclusion
The above introduction is a common method of data transfer between web pages, each with its own merits. Among them, the URL method and the form method are simple to implement, and can realize simple data transfer between web pages. They are generally of string type. They are characterized by poor security, and data transfer between two pages must be continuously accessed. Cookie can only store string type data. If you want to store more complex data types, you must first convert it to string type. The operations of the Application object and Session object are relatively complicated. Web pages with very large page views should be used in moderation, and should be cleared as much as possible after use. Otherwise, heavy use may cause the server to paralyze. Session variables are highly secure and can pass dedicated browser data. The specific application determines the choice of data transmission method, and the selection of reasonable data transmission method is a key consideration in the design of Web pages.