7.ASP built-in object Request

xiaoxiao2021-03-06  41

From this article, the author starts from the ASP built-in object, and analyzes the six internal construction objects of the ASP and the characteristics and methods of various components. Before going to learn the built-in objects and components of ASP, let us know some basic concepts, which will help you in the future. Please see the following table:

Active Server delivers a collection of server side with Windows NT. These technologies provide consistent server-party components, script models, and integrated system services for component application management, database access, transaction, and messages. Active Server Pages (ASP) Run the ActiveX script and the server script environment of the ActiveX component. Developers can combine scripts and components together to create web-based applications. ActiveX allows developers to create a rich Microsoft technical term for World Wide Web to interact with interactive components. Allows a group of unrelated languages ​​that work together in a network environment in different languages. The key element of ActiveX is the Component Object Model (COM) and Distribution Component Object Model (DCOM). These technologies have been permitted by open organization and have been ported to many platforms. ADO ACTIVE data object. A group of object-based data access interfaces optimized for Internet-based applications. ADO is based on published specifications and with in Microsoft Internet Information Server and Microsoft Visual InterDev. DSN data source name. Open Database Interface (ODBC) is used to guide the logical name of the driver or other information required to access the data. The Internet Information Server is used to connect to the name of the ODBC data source (such as SQL Server database). Event: Any operation of the program responded by the user or ActiveX control. The general event includes pressing the keyboard key to select the button and other mouse operations by using the mouse list. Programmer writes the code to respond to these operations. Object: Objects in object-oriented programming, by variables consisting of operations and data as complete entities. Objects are based on a particular model, and services that use objects in the object are accessed by a set of methods or related functions. The client can then call these methods to perform a certain operation. ODBC open database interface. Allow applications access data programming interfaces from existing data source standard specifications accessed across various cross-platform data. SQL Structured Query Language Structured Query Language. Define and access international standards for relational databases. What is an object? It doesn't mean a male companion or a woman with love. In object-oriented programming, the object refers to a variable consisting of an operation and data as a complete entity. Objects are based on a particular model, and the service used in the object uses the object to access the object by a set of methods or related functions, and the client can call these methods to perform a mode. The ActiveX component is the key to establishing a web application. Components provide objects that perform tasks in the script. The ActiveX component is a file that contains code that performs a certain or a set of tasks. Since the component can perform public tasks, the programmers do not have to create the code to execute these tasks. Components can be utilized as a script and a basic construction block based on a web application. Just know how to access the objects provided by the component, even if you write a new hand, you can write a script without understanding the components. In short, the component enables you to write a powerful script without learning programming. Components are executable code included in dynamic link library.dll or executable .exe. Components can provide one or more objects and methods and properties of objects. To use the object provided by the component, create an instance of an object and assign this new instance to a variable name. The server.createObject method using the ASP can create an instance of an object, and the variable allocation instruction using the scripting language can be named for the object instance. Such an example: SET DB = Server.createObject ("AdoDb.Connection") The variable DB here is an object instance that the ASP program creates the access database. Active Server Pages provide built-in objects that can be used in scripts.

These objects make users easier to collect information sent through the browser, respond to the browser, and storage user information, thereby enabling the object developer to get rid of many cumbersome work. The current ASP version provides six internal construction objects. Let us learn from examples. First, the Request object can use the Request object to access any HTTP request delivery, including parameters, cookies, and user authentication passed from the HTML form or get method. The REQUEST object allows you to access binary data sent to the server. Request's Syntax: Request [. Collection | Properties | Method] (Variable) Here the author selection some common object syntax for analysis 1. Form Form set by using the POST method to select the table element in the HTTP request text Value. Syntax Request.Form (Element) [(index) | .count] Parameter element Specifies the name of the table element to be retrieved. Index optional parameters, using this parameter can access one of a plurality of values ​​in a parameter. It can be any integer between 1 to Request.form (Parameter) .count. The number of elements in the count collection indexes according to the name of the parameters in the text. The value of Request.Form (Element) is an array requesting all ELEMENT values ​​in the body. Determine the number of values ​​in the parameter by calling Request.form (Element) .count. If the parameter is not associated with multiple values, the count is 1. If the parameters are not found, the count is 0. To reference a single value in a table element with multiple values, you must specify an index value. The index parameter can be any number from 1 to REQUEST.FORM (Element) .count. If one of the plurality of table parameters is referenced, the index value is not specified, the returned data will be a comma-separated string. You can use a rearray to display all data values ​​in the table request. For example, the user fills in the form by specifying several values, see the figure below. For Hobby parameters, you can retrieve these values ​​using the following scripts.

</ title> </ head> <body> <p> Please fill in your hobby </ p> <form method = "post" action = "form.asp"> <p> <input type = "text" name = "hobby" size = "20"> <br> <input type = "checkbox" name = "hobby" value = "football"> football <input type = "checkbox" name = " Hobby "Value =" Table Tennis "> Table Tennis </ P> <P> <Input Type =" Submit "Value =" Send "Name =" B1 "> <input type =" reset "value =" Refill "Name = "B2"> </ p> </ form> <% for each i in request.form ("hobby") response.write I & "<br>" Next%> </ body> </ html> Code scrapbook into the Notepad (Note "<" behind the space behind it), save to the form.asp file and run, the Request object can be displayed according to the different elements, depending on the difference you fill in or select element content. Of course, the same output can be generated using the for ... next loop, as shown below: <% for i = 1 to request.form ("hobby"). Count response.write request.form ("hobby") (i) & "<Br>" Next%> 2, queryString queryString set Retrieve the value of the variable in the HTTP query string, the HTTP query string is specified by the value after the question mark (?). Such as: <a href = "example.asp? String = this is a sample"> String Sample </ a> The value of the variable name string of "this is a sample". You can also generate a query string by sending a table or typing a query in an address box in its browser. Syntax Request.QueryString (variable) [(index) | .count] QueryString collection allows you to retrieve query_string variables in name. The value of the request.QueryString is an array of values ​​that appear in all parameters in query_string. You can determine how many values ​​have parameters by calling request.QueryString (parameter) .count. We can also use queryString to achieve the same features as the previous example.</p> <p>Just replace the Request.form section as follows: <% for each i in request.QueryString ("hobby") response.write I & "<br>" Next%> 3, cookies What is cookie? Cookie is actually a label, When you visit a web site that needs to uniquely identify your site, it will leave a tag on your hard drive. When you visit the same site, the site will look up this tag. Each Web site has its own tag, and the content of the mark can be read at any time, but can only be done by the page of the site. The cookies of each site are in different files in all the cookies of all other sites (you can find them in the cookie folder in Windows's directory). A cookie is a unique identity of the customer's tag, and the cookie can contain information shared by all pages of a web site between a dialog or several dialogues, using cookies to exchange information between the pages. The Cookies collection provided by the Request allows the user to retrieve the value of the cookie sent in the HTTP request. This feature is often used in an ASP program that requires authentication customer passwords and electronic bulletin boards, web chat rooms. Syntax Request.Cookies (cookie) [(key) | .Tribute] Parameters cookie Specifies the cookie to retrieve its value. Key Optional parameters for retrieving the value of the sub-key from the Cookie dictionary. AttribE specifies information about cookie itself. Such as: Haskeys read-only, specify whether cookies contains keywords. You can access the sub-keyword of the cookie dictionary by including a KEY value. If you do not specify a key when accessing the Cookie dictionary, all keywords are returned as a single query string. For example, if MyCookie has two keywords, first, and second, no keywords are specified when calling request.cookies, then the following string will be returned. FigSt = firstkeyvalue & second = secondkeyvalue If the client browser sends two favorite cookies, the request.cookie will return one of the deeper path structure. For example, if there are two favorite cookies, but one of the path properties is / WWW / and the other is / www / home /, the client browser simultaneously sends two cookies to / www / home / directory Then, Request.cookie will only return the second cookie. To determine if a cookie is not a cookie dictionary (Cookie has a keyword), you can use the following scripts. <% = Request.Cookies ("MyCookie"). Haskeys%> If myCookie is a cookie dictionary, the previous assignment is true. Otherwise, for False.</p> <p>Let's take a look at a cookie application example: <% nickname = request.form ("Nick") response.cookies ("nick") = nickname 'Write the username in cookie with the Response object to welcome the username. "& Request.Cookies (" NICK ") &" Guangtuan! "%> <html> <head> <meta http-equiv =" content-type "content =" text / html; charSet = GB2312> <title> Cookie </ title> <meta name = "generator" Content = "Microsoft FrontPage 3.0"> </ head> <body> <form method = "post" Action = "cookie.asp"> <p> <input type = TEXT "name =" nick "size =" 20 "> <input type =" Submit "value =" send "name =" b1 "> <input type =" reset "value =" reload "Name =" b2 "> </ p> </ form> </ body> </ html> This is actually a technique that is commonly used in a web-based BBS or CHAT ASP program that saves the name that the user fills in the start page in cookie In this way, the program can be easily called to call the NICK. 4, ServerVariables Everyone knows that the transfer protocol used when browsing the webpage in the browser is http, and some client information is recorded in the HTTP title file, such as: the customer's IP address, etc., sometimes the server needs to be different according to different The client information makes different reflections, this time you need to get the required information with the ServerVariables collection. Syntax Request.ServerVariables (server environment variable) Due to the server environment variable, the author only lists some common variables in the following table:</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-58022.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="58022" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.045</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'TUdZBuifJknSMpqbLcT_2BhYzX8rnA_2FZ4ebOKFykiG7D6XiHASwGQoLSecn4GGiim2nzyhEGT62A06zy3HlPElEQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>