ASP (English full name Active Server Pages) is a programming environment in which HTML, scripting languages, and components can be mixed to create powerful server-side Internet applications. If you have previously created a site that mixed HTML, scripting languages, and components, you can add ASP code to it. Moreover, you can also include some business logic rules through the use of components. Components can be called by scripts or other components. The following lists nineteen basic techniques for using ASP script language:
1. The current date and time command is
as follows:
<%=now%> OK
each item request.From("input"))
repomse.write item &"<br>"
next
%>
You can also use "for each x in tewuest.From" to repeatedly obtain the input values of all fields.
2. The method for ASP to obtain form (from) data input is to use a built-in object (object)—Request, which differs from get to post.
3. If you want to write it yourself in VB or other languages, and the .dll file can be used by ASP, you need to register the DLL file: enter regsbr32 *.dll under DOS.
4. Display five repeated sentences in increasingly larger font sizes.
Here is a quote:
<% for i=1 to 5 %>
<font size=<% =i %> color=#00ffff>
Fast ASP
</font>
<br>
<% next %>
5. Send the string to the client
response.write string.
The following is a quote fragment:
For example: <% response.write "Welcome" %>
6. Link to the specified URL address
response.redirect url
Here is a quote:
For example: <% response.redirect "homepage.asp">
*But if the content of this .ASP file has been transferred to the user, an error will occur when redirecting is used.
7. Combination of other languages and ASP:
Here is a quote:
For example: Good morning is displayed in the morning, and hello is displayed in the afternoon.
<%
if time>+#12:00:00 AM# and time<#12:00:00 PM #
then
greeting="Good morning!"
else
greeting="Hello!"
end if
%>
<%=greeting %>
8. Application of <script> tag in ASP
The following is a quotation fragment:
example:
<html>
<body>
<% call function1 %>
</body>
</html>
<script runat=server language=javascript>
function function1()
{
...
}
</script>
9. #include includes other files
<!--#include virtual|file="filename"-->
virtual refers to the virtual file address.
file represents an absolute file address.
For example:
The following is a quotation fragment:
<!--#include virtual="/booksamp/test.asp"-->
<!--#include file="/test/test.asp"-->
And it can be nested layer by layer. In addition, #include cannot be within <%--%>.
10. ASP method to obtain form input data: GET POST
1.get: After the client adds the data to the URL, the format is "?Field 1=Input Data 1&Field 2=Input Data 2&...", and then sends it to the server.
For example: actionwww.abc.com, the input data in the Name field is jack, and the data in the Age field is 15.
2. post: The client uses http information data to be transmitted to the server ASP:
get: Use "input data = Request.QueryString ("field name")" to retrieve the data attached to the URL.
post: Use "input data = Request.Forml" (field name ")" to read the HTTP information data field.
Here is a quote:
* Request.QueryString example: 〈A hery="aspform.asp?Name=jack&Age=15">
Click here〈/A〉〈p〉
Name:<%=request.QueryString("Name")%)
Age:<%=request.QeueryString("Age")%)
* get example·aspturm.asp:
<form action="asp1b.asp" method="get">
Name: <input type=text name="input1" value="Your name">
<p>
Features: <select name="input2">
<option>cool!
<option>handsome
<option>warmhearted
</select>
<input type=submit value="ok">
</form>
Contents of asp1b.asp
<html><body>
<% =request.querystring("input1") %> hi, your character is
<%= request.querystring("input2") %>
</body></html>
11.request.From
syntax: request.From(name)[(index)|.count]
name: field name
index: When multiple values are entered in the same field, the pointer value index specifies to be read Take the value of the same field, ranging from 1 to request.From(name).count
count: From request.From(name).count, we can know how many values are entered in the name field. If there is no such name field, count is 0 as shown in
the following example. :
The following is a quoted fragment:
<%
forI=1 to request.fron("input1").count
response.write request.From("input1")(I)&"<br>"
next
%>
If input1 has two values, both will be displayed. If index is not used to specify which one to read,
the following is a reference fragment:
<%
for
<% for each x in request.Form %>
request.From (<%=x%)=<%=request.Form
(x)%> <br>
<% next %>
12. Method to obtain the client TCP/IP port:
For example: tcp/ip port is <%=request("server_port")%>
Use server_port to get the connection port information for receiving HTTP request.
13. Through the HTTP header information of HTTP_ACCEPT_LANGUAGE, the user's language environment can be obtained.
The following example determines the locale of the client and gives different pages.
The following is a quote:
<% language=request.servervariables("HTTP_ACCEPT_LANGUAGE")
if language="en" then %>
<!--#include file="english.asp">
<% else %>
<!--#include file="china.asp">
<% end if%>
14. Home page retention period If the client browser browses the home page again within the home page retention period, the original home page content on the client's hard disk will be displayed.
response.expires[=number]
where NUMBER is the record data The retention period of the PAGE BOX, the unit is minutes.
Or: response.expiresabsolute[=2004-10-14 7:31:25[time]]
For example: set a homepage retention period to a certain date.
15. Connect Go to the specified URL address
. For example: if you want to confirm that the user has seen INDEX.HTM, you can check whether it has been seen. If it has not been confirmed, it will automatically connect to the homepage
. The following is a quotation fragment:
<%
if not session("BEEN_to_home_page") then
response.redirect "index.asp"
end if
%>
16. Determine whether you are returning to this page or entering it for the first time
. The following is a quoted fragment:
<%
if user_has_been_here_before then
response.write "<h3 align=center> Welcome Back
again"
else
response.write "Welcome!"
end if
%>
17. Display pictures and hyperlinks in the database.
The following is a quotation fragment:
<%
set conn=server.creatobject("ADODB.connection")
conn.open "myaddress"
set rs=conn.execute("select name,tel,url,image from
myaddress")
%>
<p>
<tabel>
<tr>
<% for i=0 to rs.fields.count-1 %>
<td>
<b>
<%=rs(i).name %>
</b>
</td>
<% next %>
</tr>
<% do while not rs.eof %>
<tr>
<% for i=0 to rs.fields.count-1 %>
<td valign =top>
<%
if rs(i).name="image" then
response.write "<img src="""&rs(i)&""" >"
else
if rs(i).name="url" then
response.write "<a href="""&rs(i)&""">"&rs(i)&"</a>"
else
response.write rs(i)
end if
end if
%>
</td>
<%next%>
</tr>
<% rs.movenext
loop
rs.close
conn.close
%>
</html>
18. Obtain browser information using ASP
Here is a quote:
<%
set a=server.creatobject("MSWC.BROWSERTYPE")
msg="The browser you are using is:"+a.browser+"version"+a.version
%>
<%=msg%>
19. How asp accesses cookies (using response and request)
The following is a reference fragment:
As follows: write cookies:
response.cookies("Name of cookies to be written")
="Data to be written"
Read cookies:
Read data=request.cookies("Name of cookies to be read")