|
You can not view server side scripts in a browser, you will only
see the output from ASP which is plain HTML. This is because the
scripts are executed on the server before the result is sent to
the browser.
In our school, every example has a function that displays the
hidden server side scripts. This will make it easier for you to
understand how it works.
The Basic Syntax Rule
An ASP file normally contains HTML tags, just as a standard HTML
file. In addition, an ASP file can contain server scripts,
surrounded by the delimiters <% and %>. Server
scripts are executed on the server, and can contain any
expressions, statements, procedures, or operators that are valid
for the scripting language you use.
The Response Object
The Write method of the ASP Response Object is
used to send content to the browser. For example, the following
statement sends the text "Hello World" to the browser:
Response.Write("Hello Wold").
VBScript
In ASP it is possible to use different scripting languages. The
default language in ASP is VBScript, as in this example:
<html>
<body>
<% response.write("Hello World!") %>
</body>
</html>
The example above uses the response.write function to
write Hello World! into the body of the HTML document.
JavaScript
To use JavaScript as the default scripting language, insert a
language specification at the top of the page:
<%@ language="javascript" %>
<html> <body>
<% Response.Write("Hello World!") %>
</body>
</html>
Note that - unlike VBScript - JavaScript is case sensitive. You
will have to write your ASP code with uppercase letters and
lowercase letters when the language requires it.
O ther Scripting Languages
ASP comes with VBScript and JavaScript. If you want to script in
another language, like PERL, REXX, or Python, you have to
install scripting engines for them.
Because the scripts are executed on the server, the browser that
requests the ASP file does not need to support scripting.
Examples
1. How to write some text into the body of the HTML document
with ASP.
Coding
<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
Output
Hello World!
2. How to format the text with HTML tags.
Coding
<html>
<body>
<%
response.write("<h2>Hello World!<br>This sentence uses HTML tags
to format the text!</h2>")
%>
</body>
</html>
Output
Hello World!
This sentence uses HTML tags to format the text!
|