Free tutorial : About Active Server Pages (ASP)
Free tutorial : About Active Server Pages (ASP)
What Are Active Server Pages?
What Can You Do with Active Server
Pages?
What Do Active Server Pages Look Like?
What Do Server-Side Scripts Look Like?
Do You Have to Be a Programmer to
Understand Server-Side Scripting?
Displaying the Current Date and Time
Date
Time
Now (Date and Time)
Changing the Way Date and Time are
Displayed
Month and Monthname
Day
Year
Example
Weekday and Weekdayname
Hour, Minute, and Second
What Are Active Server Pages?
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. Server-side scripts are special commands
you put in Web pages that are processed before the pages are sent from your
Personal Web Server to the Web browser of someone who's visiting your Web site.
. When you type a URL in the Address box or click a link on a Web page, you're
asking a Web server on a computer somewhere to send a file to the Web browser
(sometimes called a "client") on your computer. If that file is a
normal HTML file, it looks exactly the same when your Web browser receives it
as it did before the Web server sent it. After receiving the file, your Web
browser displays its contents as a combination of text, images, and sounds.
In the case of an Active Server Page,
the process is similar, except there's an extra processing step that takes
place just before the Web server sends the file. Before the Web server sends
the Active Server Page to the Web browser, it runs all server-side scripts
contained in the page. Some of these scripts display the current date, time,
and other information. Others process information the user has just typed into
a form, such as a page in the Web site's guestbook.
To distinguish them from normal HTML
pages, Active Server Pages are given the ".asp" extension.
What Can You Do with Active Server
Pages?
There are many things you can do
with Active Server Pages.
- 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
What Do Active Server Pages Look Like?
The appearance of an Active
Server Page depends on who or what is viewing it. To the Web browser that
receives it, an Active Server Page looks just like a normal HTML page. If a
visitor to your Web site views the source code of an Active Server Page, that's
what they see: a normal HTML page. However, the file located in the
server looks very different. In addition to text and HTML tags, you also
see server-side scripts. This is what the Active Server Page looks like to the
Web server before it is processed and sent in response to a request.
What Do Server-Side Scripts Look Like?
Server-side scripts look a lot
like HTML tags. However, instead of starting and ending with lesser-than ( <
) and greater-than ( > ) brackets, they typically start with <% and end
with %>. The <% is called an opening
tag, and the %> is called a closing
tag. In between these tags are the server-side scripts. You can insert
server-side scripts anywhere in your Web page--even inside HTML tags.
Do You Have to Be a Programmer to
Understand Server-Side Scripting?
There's a lot you can do with
server-side scripts without learning how to program. For this reason, much of
the online Help for Active Server Pages is written for people who are familiar
with HTML but aren't computer programmers.
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: ......
Free tutorial : About Active Server Pages (ASP)
0 commentaires: