Response
Like any web server, an ASP server does two basic things - it listens for requests and it generates responses based upon those requests. A request can be generated from a form, or via a URL or from a number of other sources. A response is sent to the client's browser.
The general format of the response command is response.action where action is one of several actions that can be performed. The table below details the various response commands.
| Command |
Description |
| response.write |
Writes text to the client browser |
| response.redirect |
Redirects the browser to the specified page |
| response.end |
Stops a script |
You will use the first two the most. response.write is used for writing text to the client browser. It can use plain text, HTML and/or variables. Below are some examples of the response.write command and the text that would display in the browser.
| ASP Code |
Text Displayed |
<%
response.write "Hello World!"
%>
|
Hello World! |
<%
response.write "<B>Hello World in bold!</B>"
%>
|
Hello World in bold! |
<%
name = "bob"
response.write "Hello " & name & "!"
%>
|
Hello bob! |
As can be seen from the examples, regular text (within quotation marks), text with HTML and variables can be used with the response.write command. There are also some special variations on the response.write command. The two most common are htmlencode and URLencode. Examples are below:
| ASP Code |
Text Displayed |
<%
response.write "<B>This is bold</B> while <I>This is Italic</I>"
%>
|
This is bold while This is Italic
|
<%
response.write server.htmlencode("<B>This is bold</B> while <I>This is Italic</I>")
%>
|
<B>This is bold</B> while <I>This is Italic</I> |
<%
response.write "Ewoks & Rebels = Trouble"
%>
|
Ewoks & Rebels = Trouble |
<%
response.write server.URLencode("Ewoks & Rebels = Trouble")
%>
|
Ewoks+%26+Rebels+%3D+Trouble |
Response.redirect has a similar syntax. The table below has some examples:
| ASP Code |
Resulting Action |
<%
response.redirect "www.mypage.com"
%>
|
This will cause your browser to go to www.mypage.com |
<%
newurl = "page.htm"
response.redirect newurl
%>
|
This will cause your browser to go to the variable newurl, which stores the value "page.htm". Thus, your browser will attempt to load the file page.htm from the current location. |
<%
servername = "www.mypage.com"
response.redirect servername & "/page.htm"
%>
|
Combining the variable servername and the string after it in the redirect command ("/page.htm"), this command would cause your browser to load www.mypage.com/page.htm |