1 / 14

The Request & Response object

The Request & Response object. Request Object When a browser asks for a page from a server, it is called a request. The ASP Request object is used to get information from the user. Its collections, properties, and methods are described below: Collections CollectionDescription

debradavis
Télécharger la présentation

The Request & Response object

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Request & Response object Request Object When a browser asks for a page from a server, it is called a request. The ASP Request object is used to get information from the user. Its collections, properties, and methods are described below: Collections CollectionDescription ClientCertificate Contains all the field values stored in the client certificate Cookies Contains all the cookie values sent in a HTTP request Form Contains all the form (input) values from a form that uses the post method QueryString Contains all the variable values in a HTTP query string ServerVariables Contains all the server variable values

  2. Response Object • Response Object • The ASP Response object is used to send output to the user from the server. Its collections, properties, and methods are described below: • Method Description • AddHeader Adds a new HTTP header and a value to the HTTP response • AppendToLog Adds a string to the end of the server log entry • BinaryWrite Writes data directly to the output without any character conversion • Clear Clears any buffered HTML output • End Stops processing a script, and returns the current result • Flush Sends buffered HTML output immediately • Redirect Redirects the user to a different URL • Write Writes a specified string to the output

  3. Sending Info to the server • The Request object retrieves the values that the client browser passed to the server during an HTTP request. It is used to send information to server. Using this object, you can dynamically create web pages and perform various server-side actions based on input from the user. Example

  4. Sending info back to client • The Response object is used to send output to the client from the web server. The Response.write() <html><body><%response.write("Hello World!")%></body></html> Formatted Ex

  5. Clear Method • Response.clear() <%Response.Buffer=true%><html><body><p>This is some text I want to send to the user.</p><p>No, I changed my mind. I want to clear the text.</p><%Response.Clear%></body></html>

  6. Flush Method • <%Response.Buffer=true%><html><body><p>This text will be sent to your browser when my response buffer is flushed.</p><%Response.Flush%></body></html>

  7. End Method <%@ language=VBScript %> <% Option Explicit %> <% Response.Buffer=true %> <HTML> <BODY> <% Response.Write(“Before End & Flush”) Response.Flush Response.Write(“After Flush, before End <BR>”) Response.End Response.Write(“After End”) %> </body> </html>

  8. Redirect Method • <%@ language=VBScript %> • <% Option Explicit %> • <% Response.Buffer=True %> • <HTML> • <BODY> • <% • Dim apass, bpass, cpass • bpass="bill" • cpass="bill" • apass=(bpass=cpass) • if apass then • Response.redirect "members.html" • else • Response.write "Invalid Password" • end if • %> • </body> • </html>

  9. Server Variables • This example demonstrates how to find out the visitors (yours) browser type, IP address, and more with the ServerVariables collection. Server variables can browse browser info, IP add, DNS, Method, server name, server port, server software etc. Example

  10. Controlling Information • In addition to sending HTML code back to the client, the Response object can be used to control some of the things that the browser itself does. • If you want the browser to cache the page that you are creating until a certain date, or for a certain length of time, you can use the Response object to pass the browser this information. • If the browser requested a certain page, but you really think that it should be displaying another page, you can use the Response object to tell the browser to go get another page. This could be used if you have moved a page in your site, but still want people with links to the original page to be able to get to the information. This technique is now becoming outdated with the introduction of the Transfer and Execute methods for the Server object in ASP 3.0.

  11. Content Expiration • The Expires property specifies the length of time (in minutes) before a page cached on a browser expires. If the user returns to the same page before it expires (and the page is allowed to be cached), the cached version is displayed. Example: • <% Response.Expires = 15 %> • This will result in the page expiring after 15 minutes. If you set the Expires property more then once on a single page, the server will use the shortest time period.

  12. Server.Execute • The Server.Execute method is a new ASP method, introduced with IIS 5.0 for a first time. You can execute a child ASP page with the Server.Execute and treat the child ASP page as part of the main page. What are the advantages of using Server.Execute, why did Microsoft introduce a new method? The main advantage of using Server.Execute is that you can do a dynamic conditional execution of an ASP pages. For example with the SSI includes you include file like this: <-- #include File = "c:\Inetpub\wwwroot\Your_App\include1.asp" --> <-- #include Virtual = " /Your_App/include1.asp" --> One problem with the #include command that it is processed before the page is executed, while the Server.Execute method can be used after the ASP page processing has started. The developers can conditionally execute ASP pages depending the main page business logic or on the user input with Server.Execute method. Page1Page2Page3aPage3b

  13. Transferring Control to another Page • Server.Transfer is used to transfer control to another ASP page. When it is called, all the data related to the calling page is transferred to the new page. This means that if variables of session or application scope has been given values, those values are kept in the new page. State information and values for the built-in objects are transferred, too. Also the contents of the request collections are kept and are available to the new page. • You can even perform a server.Transfer between two pages in separate applications. In this case, the value of the application variables and objects will be the same as if the second page were in the same application as the first. That is, the values of application scope variables and objects are kept after the transfer.

  14. Demonstrates How to Use Server.Execute • <%@ LANGUAGE=VBSCRIPT %><% Option Explicit %><HTML><BODY><%Response.Write( “I am in page 1 <BR>”)Server.Transfer(“page2.asp”)Response.Write(“Back in page 1”)%>< / BODY></HTML>This page is almost identical to page1.asp. the only difference is that line 7 uses a server. Transfer in place of the server.Execute. You can see the result of this listing. Notice that in this version, the third line is not printed. That is because you never return to the calling page when you do a server.Transfer. In this regard, server.Transfer may be used a bit like the Response. Redirect. Example

More Related