服务器脚本在服务器上执行,可包含你所选用的脚本语言的合法的表达式、语句、程序或者运算符。
<!DOCTYPE html>
<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
如果需要设置 JavaScript 为某个特定页面的默认脚本语言,您必须在页面的顶部插入一行语言说明:
<%@ language="javascript"%>
<!DOCTYPE html>
<html>
<body>
<%
Response.Write("Hello World!")
%>
</body>
</html>
变量:
Session 变量
Session 变量用于存储单一用户的信息,并且对一个应用程序中的所有页面均有效。存储于 Session 中的典型信息有姓名、id 和参数。
Application 变量
Application 变量同样对一个应用程序中的所有页面均有效。Application 变量用于存储一个特定的应用程序中所有用户的信息
子程序
<!DOCTYPE html>
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>Result: <%call vbproc(3,4)%></p>
</body>
</html>
表单和用户输入:
html表单:
<form method="get" action="simpleform.asp">
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br><br>
<input type="submit" value="Submit">
</form>
asp程序:
<body>
Welcome
<%
response.write(request.querystring("fname"))
response.write(" " & request.querystring("lname"))
%>
</body>
Request.QueryString 命令用于收集使用 method="get" 的表单中的值。
Request.Form 命令用于收集使用 method="post" 的表单中的值
Cookies:
"Response.Cookies" 命令用于创建 cookie。
注释:Response.Cookies 命令必须出现在 <html> 标签之前。
设置一个firstname为ALex的cookies值
<%
Response.Cookies("firstname")="Alex"
%>
向 cookie 分配属性也是可以的,比如设置 cookie 的失效时间:
<%
Response.Cookies("firstname")="Alex"
Response.Cookies("firstname").Expires=#May 10,2012#
%>
取回cookie值:
"Request.Cookies" 命令用于取回 cookie 的值。
<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>
带有键的cookie:
如果一个 cookie 包含多个值的集合,我们就可以说 cookie 带有键(Keys)。
在下面的实例中,我们将创建一个名为 "user" 的 cookie 集合。"user" cookie 带有包含用户信息的键:
<%
Response.Cookies("user")("firstname")="John"
Response.Cookies("user")("lastname")="Smith"
Response.Cookies("user")("country")="Norway"
Response.Cookies("user")("age")="25"
%>