By learning from the request object, you can learn that the request object is the information that the server side uses to get the client.
But is there a lack of server-side messaging to the client as the server interacts with the client? Object response is to hold this responsibility.
The object that is responsible for passing information to the user is response, which dynamically responds to client requests and returns dynamically generated response results to the client browser.
One, Response.Write
The Write method in response is the most frequently used one, write is written: writes the specified string to the current HTTP output.
1,write.asp
<%
Response.Write ("Hello,world" & "<br>")
Randomize
Response.Write "Any number is" &rnd () & "<br>"
%>
|
The information displayed after Response.Write can be enclosed in parentheses or written directly (note that there are spaces between the Response.Write).
Write string information or HTML code related, enclosed in quotes, and the ASP itself's function or variable is not needed, directly.
And the connection between string information, HTML code, function, or variable is a & number (for VBScript)
Above encountered a
random function rnd (), the function returns a value less than 1 but greater than or equal to 0.
Note that the random number generator is initialized with a Randomize statement without parameters before calling Rnd, which has a seed based on the system timer.
If the randomize is missing, the random seed cannot continue to be generated.
The following example uses a random function to produce a random background color effect:
<textarea class="bk" id="temp42185" rows="12"><script language=vbs> Randomize ' first Randomize produce random seed suij=rnd () ' then assign the function value to the variable Suij suij=replace (Suij, " . "," 9 ") ' then convert the decimal symbol of the variable SUIJ to the number 9 Suij=left (suij,6) ' to the left 6 bits of the variable ' document.write ' <body bgcolor=# ' &suij& ' &G t; " ' finally applied to the background color to </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
Of course, to produce random integers of the specified range, use the following formula:
Int ((upperbound-lowerbound + 1) * Rnd + lowerbound)
Here, the upperbound is the upper bound of this range, and the lowerbound is the lower bound within this range.
<textarea class="bk" id="temp33899" rows="12"><script language=vbs> do Until choose = vbno Value = Int ((100) + 60) ' produces a random number from 60 to. MsgBox Value Choose = MsgBox ("Roll again?", vbYesNo) Loop </script></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
Random function in the exam system is very useful, of course, you can also be used to shake the prize yourself, take the color also points I can do
Two, Response.End
This is a commonly used method of response the WEB server to stop processing the script and return the current result, and the remaining content in the file will not be processed.
Mainly in a page of multi-functional ASP page, in order to let the program run to this, or down the program does not need to perform the display ...
2,end.asp
<%response.write Now ()
Response.End ' program execution shows this end
Response.Write Rnd ()%>
|
Three, Response.Clear
The main purpose of this method is to clear all the HTML output in the buffer, but the method clears the response body only and does not clear the response header.
The method and the end method seem to be the opposite, and ending returns the result above, while clear clears the above execution and returns only the following results.
3,clear.asp
<%response.write Now ()
Response.Clear ' All the above procedures are cleared
Response.Write Rnd ()%>
|
Here's an example to take a closer look at the end and clear
4,end2clear.asp
<%
Filepath=request.servervariables ("Script_name")
User=request.form ("username")
Pwd=request.form ("password")
%>
<form method= "POST" action= "<%=filepath%>" >
Name:<input type= "text" name= "username" ><br>
Pwd:<input type= "password" name= "password" ><br>
<input type= "Submit" value= "Submit" >
</form>
<%
If user= "Cnbruce" and pwd= "Cnbruce" Then
Response.Write "Using the Clear method, the above program result will be cleared." "
Response.Clear ' empties the pages stored in the cache
Else
Response.Write "Using the End method, the following program will be deactivated." "
Response.End ' stops script processing immediately and prints the page in the cache
End If
%>
If you only see the "Refresh" link, the Clear method is already in effect <br>
<a href= "<%=filepath%>" > Refresh </a>
|
In the above program, when the username and password are cnbruce, the result of the clear method is found, whereas the other effect is another.
Four, Response.Redirect
The Redirect method is to have the browser redirect immediately to the URL address specified by the program. This is important to specify different pages for different customers depending on the customer's response, or to specify different pages based on different situations.
The method takes effect immediately and is not executed in subsequent scripts.
5,redirect.asp
<%response.redirect ("http://www.cnbruce.com/")%>
|
The above four use belongs to the response object's several more important
methods: Write, end, clear, redirect, etc.Of course, the method also: AddHeader, AppendToLog, BinaryWrite, Flush ...
As I said earlier, an ASP object except
Object MethodsOutside, there are
Object Properties
The object of the response
PropertyWhat do you have?
Five, Response.ContentType
The ContentType property specifies the HTTP content type of the server response. If ContentType is not specified, the default is
text/html。
6,contenttype.asp (non-text/html)
<% Response.ContentType = "text/html"%>
<% Response.ContentType = "Image/gif"%>
<% Response.ContentType = "Image/jpeg"%>
<% Response.ContentType = "Text/plain"%>
<% Response.ContentType = "Image/jpeg"%>
|
Six, Response.Charset
The Charset property attaches the character set name to the Content-type header in the Response object to set the file character encoding that the server responds to the client.
7,charset.asp
<% Response.Charset = "Big5"%>
Chinese display, but the use of Big5 traditional coding, so see is garbled.
|
Of course Response.ContentType and Response.Charset are less used. It's OK to add directly to the head header attribute.
Seven, Response.Expires
This property specifies how much time is available to buffer the stored page on the browser.
If a user returns to this page before a page expires, the page in the buffer is displayed.
However, if you set the response.expires=0, you can make the cached page expire immediately.
This is a more practical property, when the customer through the ASP's Landing page into the Web site, you should use this property to make the landing page expire immediately to ensure security.
Refer to a classic example
8,expires.asp
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now ()-1
Response.AddHeader "Pragma", "No-cache"
Response.AddHeader "Cache-control", "private"
Response.CacheControl = "No-cache"
%>
|
Eight, Response.Status
Sets the value of the status row that the server is responding to. Response.status= "Status Description string", the string can be a three-bit integer or a string of descriptive text, but must be anti-
9,status.asp
<% Response.Status = "401 Unauthorized"%>
|
Nine, Response.Buffer
The more important one, the value is true or false. This property indicates whether the page output is buffered.
Reference: When the page output is buffered, the server sends the response to the client browser only after all server scripts for the current page have been processed or the Flush or End method is invoked, and the server will not be able to set the buffer property after it has been sent to the client browser. You should therefore call Response.Buffer on the first line of the. asp file.
For the Response object
PropertyAnd
MethodFirst here, one left.
Data Collection, that is, cookies.
Go ahead and see the cookie lecture.
Examples of application problems
form Outlook mail
<textarea class="bk" id="temp11873" rows="12"><style> input{border:1px solid Navy width:150} </style> <script> function Test () {var newtitle=ti Tle.value; var Newcontent=content.value; document.location.href= "mailto:" +aaa.value+ "cc=" +bbb.value+ "&bcc=" +ccc.value+ "&subject=" +NewTitle+ " &body= "+newcontent; {</script> <pre> <font color=red> recipients: </font><input name=aaa><br> <font color= Red>: </font><input name=bbb><br> <font color=red> Blind to send: </font><input NAME=CCC ><br> <font color=red> Theme: </font><input name=title><br> <font color=red> content: </font></pre><p> <textarea cols=30 rows=10 name=content></textarea><br> < Input Type=button value= "send" onclick= "Test ()" ></textarea>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]
ASP's
<%
Submitname=request.form ("Submit")
If submitname= "Submit" Then
Email=request.form ("email")
Cc=request.form ("CC")
Subject=request.form ("Subject")
Body=request.form ("Body")
Response.Redirect ("mailto:" &email& "cc=" &cc& "&subject=" &subject& "&body=" & Body
Else
%>
<form name= "Form1" method= "Post" action= "email.asp" >
Email:<input name= "Email" ><br>
Cc:<input name= "CC" ><br>
Subject:<input name= "Subject" ><br>
Body:<input name= "Body" ><br>
<input type= "Submit" name= "submit" value= "Submit" >
</form>
<%end if%>
|