VKS-LEARNING HUB

Home » Class XII » MMWT-XII » ASP-Basics

ASP-Basics

Active Server Pages (ASPs) are Web pages that contain server-side scripts in addition to the usual mixture of text and HTML (Hypertext Markup Language) tags.

What is ASP?

ASP-Stands for Active Server Pages is a server-side scripting environment that can be used to create and run dynamic and interactive Web server applications. ASP are processed by server rather than by the client. The Web Server does all the work involved in generating the HTML pages sent to browsers.

An ASP File has the extension “.asp”

Default language for server-side scripting with ASP is VBScript

Other Language is JAVA SCRIPT

ASP Engine ?

The ASP engine reads the ASP file, line by line, and executes the scripts in the file. Finally, the ASP file is returned to the browser as plain HTML

The following provides a breif summary of the steps involved in processing ASP files:

  1. A web browser requests an ASP file
  2. The web server recives the request and loads the ASP file.
  3. The server executes the code inside the ASP file. Any output from this processed ASP code is sent to the browser in HTML format, along with any other HTML content.

What Can You Do with Active Server Pages?

There are many things you can do with Active Server Pages.

There’s no limit to what you can accomplish with Active Server Pages. just about any Web site that exists on the Internet today could have been created with Active Server Pages.  The follow­ing list shows some simple examples of what you can do:-

  • Include rotating banner advertisements on the Web pages of your Web site.
  • Retrieve information entered into an HTML form and store that information in a database.
  • Create personalized Web pages that display different content to different users.
  • Add hit counters to one or more pages of your Web site.
  • Display different Web pages, depending on the capability of a user’s browser.
  • Link together multiple Web pages in such a way that they can be navigated easily.
  • Track information about user activity at your Web site and save that information in a custom log file.
  • You can display date, time, and other information in different ways.
  • You can make a survey form and ask people who visit your site to fill it out, send emails, save the information to a file, etc

Equivalent Tools of ASP

Java Server Pages (JSP)

Personal Home Pages (PHP)

Common Gateway Interface (CGI)

ColdFussion

HTML

ASP

HTML is a client-side language that is developed and outputted like a “website” by a browser – not a server. It consists of tags to create elements and objects. ASP is a server-side language that outputs other languages (or just pure text) dynamically – depending on how functions and queries turn out, how variables are compared to one another, and etc.
It requires only Browser to run HTML File It requires Web Server like IIS to run ASP File
It is saved with .Html or .Htm extension ASP File is saved with .asp extension

CLIENT SIDE SCRIPTING

SERVER SIDE SCRIPTING

Client side scripting cannot connect to databases that reside on the web server Server side scripting can connect to databases that reside on the web server
client side cannot access settings belong to Web server Server side scripting can access settings belong to Web server like file system that reside at the web server
Any user in the world can view the full script by simple going to page source. Nobody can view the programming code of server side scripting.
 VBSCRIPT, JavaScript, and CSS PHP, ASP, JSP, Perl, Ruby

Displaying the Current Date and Time

The date and time described in this section are those that are on the server.

Date

To display the current date by itself in a Web page, type:

<% =date %>

at the point where you want it to appear. When you view the page in your browser, you should see something like this:

Thu, Jan 23, 1997

Note: Even though “=date” is a short script, it’s actually made up of two parts. The “date” part tells the server, “Get me the date.” The equal sign (=) tells the server to display the date in the Web page. If you typed just:

<% date %>

the server would get the current date from your system, but that’s all. It wouldn’t display it. There are times when it makes sense to use an ASP function without the equal sign.

Time

To display the current time by itself, type:

<% =time %>

where you want it to appear. When you view the page, you should see something like this:

4:19:46 PM

Now (Date and Time)

To display the current date and time, type:

<% =now %>

where you want them to appear. When you view the page, you should see something like this:

1/23/97 4:19:46 PM

Changing the Way Date and Time are Displayed

You can also use Active Server Pages (ASP) functions to customize the way the current date and time are displayed on your Web page. To do this, use the now function together with the following formatting functions.

Month and Monthname

To display the number of the current month in a Web page, type:

<% =month(now) %>

where you want it to appear. When you view the page in your browser, you’ll see a 1 if the current month is January, 2 if it’s February, and so on.

To display the name of the current month, type:

<% =monthname(month(now)) %>

where you want it to appear.

Day

To display the day of the current month, type:

<% =day(now) %>

where you want it to appear. When you view the page, you’ll see a number between 1 and 31.

Year

To display the current year, type:

<% =year(now) %>

where you want it to appear.

Example

Suppose you wanted to display today’s date as day/month/year instead of month/day/year. To do so, you would use the day, month, and year ASP functions together, by typing:

<% =day(now) %>/<% =month(now) %>/<% =year(now) %>

When you viewed the page, you would see something like this:

23/1/1997

Later we’ll see how you can change this so only the last two digits of the year are displayed, like this:

23/1/97

Weekday and Weekdayname

To display the day of the week as a number from 1 to 7 in a Web page, type:

<% =weekday(now) %>

where you want it to appear. When you view the page in Internet Explorer, you’ll see a 1 if today is Sunday, 2 if it’s Monday, and so on.

To display the day of the week by name, type:

<% =weekdayname(weekday(now)) %>

where you want it to appear.

Hour, Minute, and Second

To display just the hour part of the current time, type:

<% =hour(now) %>

where you want it to appear. The hour function is based on a 24-hour clock. When you view the page, you’ll see a number between 0 and 23.

To display just the minutes part of the current time, type:

<% =minute(now) %>

where you want it to appear. When you view the page, you’ll see a number between 0 and 59.

To display just the seconds part of the current time, type:

<% =second(now) %>

where you want it to appear. When you view the page, you’ll see a number between 0 and 59.

Example

Try typing this into a Web page:

The time is <% =time %>. That means it's <% =minute(now) %> 
minutes past <% =hour(now) %> o'clock.

When you view the page in Internet Explorer, you should see something like this:

The time is 1:36:05 PM. That means it’s 36 minutes past 13 o’clock.

Remember, the hour function is based on a 24-hour clock. Later we’ll see how to convert from the 24-hour clock to a 12-hour clock.

Important Example  for Exam point of view

Another Way to Display the Time

In an earlier example, we wrote a server-side script to display the current time in words, such as: “The time is 36 minutes and 5 seconds past 13 o’clock.” This script used the ASP hour function, which returns just the hour part of the current time, based on a 24-hour clock.

In this example, we’ll see how to change 24-hour clock times such as “13 o’clock” to 12-hour clock times (“1 o’clock PM”). To do this, we’ll need to make the server-side script that uses the hour function a little more complicated. Instead of

<% =hour(now) %> o'clock

we’ll need to write a script that looks at the hour and does one of the following:

  • If the hour is 0 (zero), the script displays “midnight.”
  • If the hour is 12, the script displays “noon.”
  • If the hour is between 1 and 11, the script doesn’t change it, but it displays “AM” after “o’clock.”
  • If the hour is between 13 and 23, the script subtracts 12 (to make it a number between 1 and 11) and displays “PM” after “o’clock.”

The script is shown below. It isn’t written quite the way a programmer would write it, but it works, and it’s fairly easy to understand, since it follows the items in the bulleted list above exactly.

The hour is 
<% if hour(now) = 0 then %>
   midnight.
<% end if 
   if hour(now) = 12 then %>
  noon.
<% end if 
   if (hour(now) >= 1) and (hour(now) <= 11) then %>
    <% =hour(now) %> o'clock AM.
<% end if 
   if (hour(now) >= 13) and (hour(now) <= 23) then %>
    <% =hour(now) - 12 %> o'clock PM.
<% end if %>

If you type (or better yet, cut-and-paste) this script in a Web page, when you view the page, you should see something like this:

The hour is 4 o’clock PM.


Leave a comment