ASP introduction and five built-in objects

zhaozj2021-02-17  54

Order

1. ASP foundation

2. Five major objects of ASP

3. REQUEST object

4. Response object

5. Server object

6. APPLICATION object

7. Session object

1. ASP foundation

Microsoft Active Server Pages, the ASP, namely the reader, is a set of Microsoft-developed server-side script environments, and the ASP is included in IIS, and the latest version of ASP 3.0 is included in IIS 5.0. With ASP, you can establish dynamic, interactive and efficient web server applications with HTML web pages, ASP instructions, and ActiveX controls. With ASP, you don't have to worry if the customer's browser can run the code you write, because all programs will be executed on the server, including all scripts embedded in ordinary HTML. When the program is executed, the server only returns the result of the execution to the client browser, which also reduces the burden on the client browser, which greatly improves the speed of interaction.

The ASP summarizes the following features:

Ø Use VBScript, JScript, etc., easy-to-understand scripting languages, combine HTML code to complete the website's application.

Ø No need to compile, easy to write, can be executed directly on the server side.

Ø You can write it with a normal text editor. In order to better conduct team development, Microsoft specially develops a development tool Visual InterDev, which is an integrated web application development system, including development, distribution, and management database driver. All features required for web application software.

Ø The script VBScript used by the ASP is executed in the web server, and the user-end browser does not need to perform these scripting languages.

Ø The source of ASP will not be passed to the customer browser, so that the written program can be plagiarized by others, thereby improving the security of the website.

Ø ActiveX Server Components has unlimited expansion. You can use Visual Basic, Java, Visual C , COBOL and other programming languages ​​to write the ActiveX Server Component you need.

A plain text, HTML tag, and script command can be included in the ASP program. You only need to put the .asp program in a virtual directory of the web server (this directory must have executable permissions), you can access the ASP program by WWW.

Learning the basics of ASP to master:

Ø Learn the use of Microsoft Visual InterDev software.

Ø Installation and use of the ASP server.

Ø ASP is included in IIS, IIS 4.0 containing IIS 2.0, and the IIS 5.0 of Windows 2000 is included in IIS 3.0. If it is a normal Windows 98 user, it doesn't matter. Microsoft has also developed a server Personal Web Server for learning ASP. It is generally included in the formal version of the formal version of the Windows 98, as long as the Personal Web Server, Windows 98 Users can learn ASP programming.

Ø Proficiency in HTTP and HTML.

Ø Proficiency in VBScript or JavaScript.

Ø Proficiency in database knowledge. For example: Microsoft SQL Server, be familiar with ADO and ODBC, familiar with Transact-SQL language.

2. Five major objects of ASP

Request Object

Collection: QueryString, Form, Cookies, ServerVariable Main role: Read data in the submitted form or cookies.

Response Object

Property: Buffer, Cookies, ContentType, Expires, Expiresabsolute, Status, IsclientConnected, CacheControl

Method: Write, Redirect, end, flush, cookies, binarywrite, addheader, appendtolog

Main role: Output text, data, and cookies to the browser, and control each stage during the transfer web page.

Server Object

Property: ScriptTimeout

Method: CreateObject, MAPPATH, URLENCODE, HTMLENCODE

Main role: Creating a COM object and scripting component, and the like.

Application Object

Properties: LOCK and UNLOCK

The main role: Application object is used to place shared information between multiple users in the same application.

Session Object

Property: SessionID and TIMEOUT

Method: Abandon

Main role: maintain data for a single user.

3. REQUEST object

The Resquest object represents a request packet sent by each client to HTTP. In fact, the functionality of the Request object is one-way, which can only receive the data submitted by the client web page, just opposite to the RESPONSE object.

ResQuest Receives Data When two collection querystring and form retrieves the data of the form, which collection is used, depending on the Method property of the HTTP form submitted by the web page, when the Method property value is "Get", with querystring, Method The attribute value is "POST" with form. When the specific collection name is omitted, the ASP searches the following sequence: queryString -> form -> cookie -> ServerVariables.

When the data is submitted to the log.asp file of the server side, use the request object in log.asp to get the data submitted by the user, and determine if the user is legal. Log.asp files are as follows:

<%

DIM User

DIM Passwd

User = Request.QueryString ("logID")

PASSWD = Request.QueryString ("Password")

IF user = "jeff" then

if Passwd = "123456" THEN

Response.write "Sign in success!"

Else

Response.write "password error!" End if

Else

Response.write "User Name Error!"

END IF

%>

In this example, the Method property uses the GET method, so use the request.QueryString to receive data. If the Method property uses the POST method, use the request.form to receive data.

The ServerVariables collection can be used to provide headers related to the HTTP request, and its reference format is:

Request.ServerVariables ("Keyword")

"" Keywords are:

Remote_addr -> You can know the client's IP

URL -> Get the URL path of the system

PATH_TRANSLATED -> Current Active Server Page's true address

HTTP_UA_OS -> The operating system where the browser is located

4. Response object

The Response object is used to send data to the client browser. The user can use the object to send the server's data to the user-end browser in HTML, which forms a pair of receptions, transmitted data, which is implemented with the request. Foundation. The following describes the properties and methods of it.

Buffer attribute

This property is used to specify whether the page output is to be used to use the buffer, the default value is false. When it is True, the result is output to the browser until the entire Active Server Page executes. Such as:

<% Response.buffer = true%>

Buffer Example </ Title></p> <p></ hEAD></p> <p><body></p> <p><%</p> <p>For i = 1 to 500</p> <p>Response.write (I & "<br>)</p> <p>NEXT</p> <p>%></p> <p></ body></p> <p></ html></p> <p>When this page is executed, all the contents of the entire home page will be displayed on the browser at the same time, and this home page exists in the cache area until the script is completed.</p> <p>Expires property</p> <p>This attribute is used to set the length of time (in minutes) of the browser cache page, and must be refreshed on the server. With the following settings:</p> <p><% Response.expires = 0%></p> <p>By adding this line of code in the ASP file, requesting each request is refreshing page, because Response will expire each time you receive the page.</p> <p>Write method</p> <p>This method sends data to the client browser, such as:</p> <p><% Response.write "Hello, World!"%></p> <p>Redirect method</p> <p>This method allows the browser to reposition to another URL so that when a customer issues a web request, the client's browser type has been determined, and the customer is relocated to the corresponding page. Such as:</p> <p><html></p> <p><HEAD></p> <p><title> redirect example </ title></p> <p></ hEAD></p> <p><body></p> <p><form aciton = "formjump.asp" method = "post"></p> <p><select name = "wheretogo"></p> <p><option selected value = "fun"> Fun </ option> <option value = "news"> news </ option></p> <p><option value = "Sample"> Sample </ option></p> <p></ select></p> <p><Input Type = Submit Name = "Jump" Value = "Jump"></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>The above is the form of submit, the following is the filemjump.asp for processing forms:</p> <p><% response.buff = True%></p> <p><html></p> <p><HEAD></p> <p><title> redirect example </ title></p> <p></ hEAD></p> <p><body></p> <p><%</p> <p>Thisurl = "http://jefenet.yesky.net/"</p> <p>Where = Request.form ("WHERETOGO")</p> <p>Select Case Where</p> <p>Case "fun"</p> <p>Response.Redirect thisurl & "/fun/default.asp"</p> <p>Case "news"</p> <p>Response.Redirect thisURL & "/news/default.asp"</p> <p>Case "Sample"</p> <p>Response.Redirect thisURL & "/sample/default.asp"</p> <p>End SELECT</p> <p>%></p> <p></ body></p> <p><html></p> <p>This example is when the user selects, press the "Jump" button to submit the form, and the server is positioned to the corresponding URL after calling the Formjump.asp judgment after receiving the application. However, it is important to note that the HTTP title has been written to the customer browser, and the modification of any HTTP title must be made as follows before writing to page content:</p> <p>Start in the file <@ language = ..> Repair:</p> <p>Response.buffer = TRUE</p> <p>At the end:</p> <p>Response.flush</p> <p>Here FLUSH is a method of response, which must be used when the buffer property is set to TRUE, otherwise a run mode error will be generated. Another CLEAR method is also used to clear the cached page, which is also available when the buffer property is set to TRUE.</p> <p>End method</p> <p>This method is used to inform Active Server to stop processing ASP files when encountering the method. If the buffer attribute of the Response object is set to True, then the End method is sent to the customer in the cache and clear the punch. So to cancel all output people to customers, you can clear the buffer before using the END method. Such as:</p> <p><%</p> <p>Response.buffer = TRUE</p> <p>ON Error ResMe next</p> <p>Err.clear</p> <p>IF Err.Number <> 0 THEN</p> <p>Response.clear</p> <p>Response.end</p> <p>END IF</p> <p>%></p> <p>5. Server object</p> <p>Server object is a very important object in ASP, and many advanced features are done by it. It provides the use of Active Server Pages and methods, which I mainly introduce several common methods. MAPPATH method</p> <p>This method returns a relative path or physical path to the specified file. If PATH begins with one (/) or (/), the mappath method will deepen the PATH as a complete virtual path when the mappath method returns the path. If the PATH is not started with a slash, the mappath method returns the path to the existing path in the .asp file.</p> <p>Such as: Test.asp file is under C: / INETPUB / WWWROOT / MyHome, the C: / INETPUB / WWWROOT is the host directory of the server, and Test.asp contains the following script:</p> <p><% Response.write server.mappath (Request.ServerVariables ("Path_INFO")%></p> <p>Output: c: /inetpub/wwroot/myhome/test.asp</p> <p>It is also possible to get this result.</p> <p><% Response.write server.mappath ("myhome / test.asp")%></p> <p>CreateObject method</p> <p>This method is the most important way in the Server object, you can see it later, many features have to be used. It is used to create an ActiveX component that has been registered to the server. This is a very characteristic because you can extend the ActiveX capabilities by using the ActiveX component.</p> <p>The method used to create a server is as follows: Server.createObject ("Componentname")</p> <p>The components used to create can be all the built-in components that all ActiveX can be used, which is actually all ActiveX components that exist in the server.</p> <p>6. APPLICATION object</p> <p>The Application object is an application-level object to share information between all users, and can maintain data during the Web application running.</p> <p>Application's properties:</p> <p>The Application object does not have built-in properties, but we can create its properties yourself.</p> <p><% Application ("Properties Name) = Value%></p> <p>In fact, most of the Application variables are stored in the Contents collection, when you create a new Application variable, actually adding an item in the Contents collection. The following two scripts are equivalent:</p> <p><% Application ("greeting") = "Hello!"%></p> <p>Or <% Application.Contents ("Greeting") = "Hello!"</p> <p>Since the Application variable exists in a collection, if all it wants to display, the method we have used multiple times, such as for Each loops.</p> <p><%</p> <p>For Each Item in Application.Contents</p> <p>Response.write ("<br>" & item & applibility.contents (item)</p> <p>NEXT</p> <p>%></p> <p>Application method:</p> <p>Application method only two methods: one is LOCK, the other is UNLOCK. Where the LOCK method is used to ensure that only one user can operate on the Application. UNLOCK is used to cancel the limit of the LOCK method. Such as:</p> <p><%</p> <p>Application.lock</p> <p>Application ("visitor_num") = Application ("visitor_num") 1Application.unlock</p> <p>%></p> <p>Application's event:</p> <p>Ø Application_OnStart (), triggered when the event application starts.</p> <p>Ø Application_ONEND (), this event application is triggered at the end of the application.</p> <p>These two events must be defined in the global.asp file, generally defining the function of the connection data in both events and placed in Global.asp. E.g:</p> <p>SUB Application_onstart</p> <p>Application ("TT18_Connectionstring") = "driver = {sqlserver};</p> <p>Server = Jeff; UID = SA; PWD =; Database = TEST "</p> <p>End Sub</p> <p>An array can be defined as an Application object, but this array can only be saved as an object without using Application (0) to remove its value. You can define a temporary array implementation. Such as:</p> <p><%</p> <p>DIM array ()</p> <p>Array = Application ("array")</p> <p>For i = 0 to ubound (array)</p> <p>Response.write Array (i)</p> <p>Next I</p> <p>%></p> <p>Also modify this Application object can also define a temporary array, assign the Application object to an array, then modify the elements of this array, and finally assign an array to the Application object. Such as:</p> <p><%</p> <p>DIM array ()</p> <p>Array = Application ("array")</p> <p>Array (0) = "jeff"</p> <p>Array (1) = "zhu"</p> <p>.</p> <p>.</p> <p>Application.lock</p> <p>Application ("array" = array</p> <p>Application.unlock</p> <p>%></p> <p>7. Session object</p> <p>The session actually refers to the time of visitors from reaching a particular home page to leave. Each visitors will receive a session separately. In a web application, when a user accesses the app, the SESSION type variable can share data in all pages of the web application; if another user also accesss the web app, he also has its own session. Variables, but the two users cannot share information through the session variable, and the change of the Application type can achieve information between the plurality of users to share information in all pages.</p> <p>a> sessionID attribute</p> <p>This attribute returns the unique flag of the current session to assign different numbers for each session. I have encountered the control problem of users during the development process. The function it wants is to be a module for a website. When a member is logged in, another person is logged in with the same member name, and cannot be viewed. That is to say a member name, only one person can browse this module alone. I have implemented control by using the member name (assuming UserID, unique) and sessionID. When a member logs in, a session login status is sent to this member such as: session ("status") = "logged", and writes the session.SessionID of this member to the database. When he wants to browse this module, first determine whether it is logged in, if it has been logged in, it is determined whether it is the same as the database record, if it is different, if it is different, it cannot be accessed. Thus, when another user logs in with the same member name, then recorded in the database is the new sessionID, and the former cannot pass the inspection when accessing this module. This realizes a member name to browse a module alone at the same time. This feature has a special role in some toll websites, which prevents a member named many people to browse, and protect the company for the company. B> .timeout attribute</p> <p>This property is used to define the time limit of the user session object. If the user does not refresh the webpage in the specified time, the session object will terminate. Generally, it is 20 minutes.</p> <p>C> .ABandon method</p> <p>This method is the only way to session objects, which can clear the session object to eliminate the user's session object and release the resources they occupy. Such as: <% session.abandon%></p> <p>D> .Session_onstart and session_onend events</p> <p>Like Application, the session_onstart event is triggered each time the object's routine is started, and then run the processing process of the session_onstart event. That is, when the server receives the HTTP request of the URL in the application, triggering this event and establishes a session object. Similarly, this event must also be set in the global.asa file.</p> <p>When calling the session.abandon method or not refreshed during Timeout, this triggers the session_onend event, and then performs the script inside. The session variable is associated with a specific user, and the session variable assigned to a user is completely independent of the session variables of other users, and there is no interaction.</p> <p>SESSION application example:</p> <p>As with Application, an array that is defined as a Session type can only use the entire array as an object, and the user cannot directly change the value of an element in the session array. In order to create a session array, you need to define an ordinary array and assign each element of it, and finally define it as an session array. Such as:</p> <p><%</p> <p>DIM array ()</p> <p>Array = Array ("Jeff", "Zhu", "Male")</p> <p>Session ("info") = array</p> <p>Response.write session ("info") (0) & "-"</p> <p>Response.write session ("Info") (1) & "-"</p> <p>Response.write session ("info") (2) & "<br>"</p> <p>%></p> <p><hr> <%</p> <p>Array (0) = "jun"</p> <p>Array (1) = "li"</p> <p>Array (2) = "female"</p> <p>Session ("info") = array</p> <p>Response.write session ("info") (0) & "-"</p> <p>Response.write session ("Info") (1) & "-"</p> <p>Response.write session ("info") (2) & "<br>"</p> <p>%></p> <p>The above program output is:</p> <p>Jeff-zhu-male</p> <p>_____________</p> <p>Jun-li-female</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-29563.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="29563" 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.050</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 = 'XSitMldJjEyTITYzHivB4hrVusoIag4hrU3IxTMJMaDeZzEYmrLn6m1dCjUHSwkr_2BaX4Z_2BNbym4mj2TvOj14bQ_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>