An example of ASP basic Tutorials learning ASP Response objects

Source: Internet
Author: User
Tags character set empty flush header html tags log browser cache
response| Objects | Basic Tutorials

The result of an ASP Response object used to send output from the server to the user.

Instance

writing text Using ASP

This example shows how to use ASP to write text.

<body>
<%
Response.Write ("Hello world!")
%>
</body>

format text using HTML tags in asp

This example demonstrates how to use ASP to combine text and HTML tags.

<body>
<%
Response.Write ("%>
<%
Response.Write ("<p style= ' color: #0000ff ' >this text is styled with the style attribute!</p>")
%>
</body>

redirect the user to a different URL

This example shows how to redirect a user to another URL.

<%
If Request.Form ("select") <> "then
Response.Redirect (Request.Form ("select"))
End If
%>
<body>
<form action= "/example/aspe/demo_aspe_redirect.asp" method= "POST" >
<input type= "Radio" name= "select"
Value= "/example/aspe/demo_aspe_server.asp" >
Server example<br>
<input type= "Radio" name= "select"
Value= "/example/aspe/demo_aspe_text.asp" >
Text example<br><br>
<input type= "Submit" value= "go!" >
</form>
</body>

Show Random links

This example shows a hyperlink that displays one of the two links each time you load the page.

<body>
<%
Randomize ()
R=rnd ()
If r>0.5 Then
Response.Write ("<a href= ' http://webjx.com ' >webjx.com</a>")
Else
Response.Write ("<a href= ' http://www.webjx.com ' >www.webjx.com</a>")
End If
%>
<p>
This example demonstrates a link, which you load the page, it'll display
One of two links:webjx.com! OR www.webjx.com! There is a 50% chance for
Each of them.
</p>
</body>

Control Caching

This example shows how to control caching.

<%
Response.buffer=true
%>
<body>
<p>
This text would be sent to your browser the when I response the buffer is flushed.
</p>
<%
Response.Flush
%>
</body>

Empty Cache

This example shows how to empty the cache.

<%
Response.buffer=true
%>
<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>

terminates the script and returns the result during the process

This example shows how to break the running of a script during a process.

<body>
<p>i am writing some text. This text would never be<br>
<%
Response.End
%>
finished! It ' s too late to write more!</p>
</body>

set how many minutes to cache the page in the browser before the page fails

This example shows how to specify how long the page will be cached in the browser before it is invalidated.

<%Response.Expires=-1%>
<body>
<p>this page is refreshed with each access!</p>
</body>

set the expiration date or time of the page cache in the browser

This example shows how to specify a date or time when a page is cached in the browser

<%
response.expiresabsolute= #May 05,2001 05:30:30#
%>
<body>
<p>this page would expire on May, 2001 05:30:30!</p>
</body>

Check if the user is still connected to the server

This example shows how to check if a user has been disconnected from the server.

<body>
<%
If Response.isclientconnected=true Then
Response.Write ("The user is still connected!")
Else
Response.Write ("The user is not connected!")
End If
%>
</body>

Set Content Type

This example shows how to specify the type of content.

<%
Response.contenttype= "Text/html"
%>
<body>
<p>this is some text</p>
</body>

Setting the character set

This example shows how to specify the name of a character set.

<%
response.charset= "Iso8859-1"
%>
<body>
<p>this is some text</p>
</body>

Response objects

The result of an ASP Response object used to send output from the server to the user. Its set, properties, and methods are as follows:

Set

Collection Description
Cookies Sets the value of the cookie. If the cookie does not exist, create a cookie and set the specified value.

Property

Property
Description
Buffer Specify whether to buffer the output of the page
CacheControl Sets whether the proxy server can buffer output generated by ASP.
Charset Appends the name of the character set to the Content-type header in the response object.
ContentType Sets the HTTP content type of the response object.
Expires Sets the browser cache time (in minutes) before the page expires
ExpiresAbsolute Sets the date and time when the page cache is invalidated.
IsClientConnected Indicates whether the client has been disconnected from the server.
Pics Appends a value to the PICS flag of the response header.
Status Specify the value of the status row returned by the server.

Method

method
Description
AddHeader Add a new HTTP header and value to the HTTP response
AppendToLog Add a string to the end of the server log project (server log entry)
BinaryWrite Write data directly to output without any character conversions
Clear Clear buffered HTML output
End Stops processing the script and returns the current result
Flush Send buffered HTML output now
Redirect Redirect user to another URL
Write Writes the specified string to the output



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.