How to create your first ASP script

Now, let's write a simple ASP program to print the following message: "Welcome to ASP!!" First, recall the browser receives only the output from the Web-server. This means we must have some HTML code in our ASP example program to see the results on a browser. Second, HTML code can be used in an ASP file. Here is an example:

<html>
<title>My first ASP page </title>
<body>
<% Response.write "Welcome to ASP!!" %>
</body>
</html>

Notice we begin with the usual HTML tags: <html>, <title>, and <body>. If we want our results to be displayed on the client-side, we must use the HTML tag. The ASP tag <% was opened last and it is the one that is closed first.

The ASP code begins with <% tag. To print the message, we use the Response.Write object. Respone.Write is an ASP command to for displaying information on the browser. VBScript is not case sensitive. RESPONSE.WRITE will also display the message. The message that we want to display should be enclosed inside the double quotations "". Because we want to print "Welcome to ASP!!", our code looks like Response.write "Welcome to ASP!!"

The %> tag ends the ASP code. Again, ASP code should be enclosed inside of this opening tag <% and the closing tag %>. You should type this code in Notepad or in any other text editor you prefer. Then save it with an .asp file extension. This file should be saved in the inetpub directory under the wwwroot folder. For example, you might save it as firstPage.asp in the wwwroot folder.

Once you have opened a browser window, just type in the URL of the page you are trying to access. The URL should look something like this: http://localhost/firstPage.asp, which means we are accessing a file called "firstPage.asp" from our local machine. When you are requesting this page, you are acting as a client, when the server receives this request it begins to process the file, in this case, firstPage.asp.

Figure 1 Output of the first ASP Script
Figure 1 Output of the first ASP Script

The ASP engine processes this request because our file ends with an .asp extension. It is the ASP engine responsibility to process the code between the ASP tags. In this case, a message is printed, enclosed in quotations after the response.write object. The processed output is simply an HTML text and is sent back to the client. The client displays the message, as normal HTML text, as shown in figure 1.