Basic tips for sharing 19 ASP scripting languages

Source: Internet
Author: User

ASP (full name Active Server Pages) is a programming environment where you can mix HTML, scripting languages, and components to create server-side powerful Internet applications. If you have previously created a site that mixes HTML, scripting languages, and components, you can add ASP program code to it. Also, you can include some business logic rules by using components. A component can be called by a script program or by another component. The following is a list of the basic techniques used in 19 ASP scripting languages:
1. The current date-time command is

The following is a reference fragment:
<%=now%> can
Each item request. From ("Input"))
Repomse.write Item & "<br>"
Next
%>

Also available for each x in Tewuest. From "repeatedly gets the input values for all fields.

The 2.ASP method of obtaining a tabular (from) data input is to use a built-in object-requect, which varies by get,post.

3. If you want to write in VB or other languages, the. dll file is used by the ASP to register the DLL file: dos input Regsbr32 *.dll.

4. Display five repeating sentences, the font is getting larger and bigger.

The following is a reference fragment:
<% for I=1 to 5%>
<font size=<% =i%> color= #00ffff >
Fast ASP
</font>
<br>
<% Next%>

5. Transfer the string to the client

Response.Write string

The following is a reference fragment:
such as: <% Response.Write "Welcome"%>

6. Link to the specified URL address

Response.Redirect URL
The following is a reference fragment:
such as: <% Response.Redirect "homepage.asp" >

* But if this. If the ASP's file content has been transmitted to the user, the error will occur when using redirect again.

7. Integration of other languages with ASP:
The following is a reference fragment:
Such as: Morning display Good morning, afternoon display Hello
<%
If time>+ #12:00:00 am# and time< #12:00:00 PM #
Then
Greeting= "Good morning!"
Else
greeting= "Hello!"
End If
%>
<%=greeting%>

8. The application of <script> tag in ASP

The following is a reference fragment:
Cases:
<body>
<% Call Function1%>
</body>
<script Runat=server language=javascript>
function Function1 ()
{
...
}
</script>

9. #include including other documents

<!--#include virtual|file= "filename"--

Virtual refers to a fictitious file address.

File represents an absolute document address.

Such as:

The following is a reference fragment:
<!--#include virtual= "/booksamp/test.asp"-
<!--#include file= "/test/test.asp"-

and can be nested in layers. Another # include cannot be within <%--%>.

10.ASP How to obtain tabular input data: Get POST

A. Get: The user adds data to the URL, in the format "? field 1 = Input data 1& field 2 = input data 2&amp ...", and then send it to the server.

For example: actionwww.abc.com, field name input data is Jack, field age data is 15.

Two. Post: The client is routed to the server ASP with HTTP information data:

Get: Use input data = request.querystring (field name) to remove the data appended to the URL.

Post: Use "input data =request.forml" (Field name ")" to read the HTTP Information data field.
The following is a reference fragment:
* Request.QueryString Example
such as: 〈a hery= "aspform.asp? Name=jack&age=15 ">
Click here to 〈/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>
Asp1b.asp's Content
<% =request.querystring ("input1")%> Hi, your character is
<%= request.querystring ("Input2")%>
</body>
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 the value to read from the same field, ranging from 1 to request. From (name). Count

Count: By request. From (name). Count indicates that the name field enters several values, and if there is no this name field, Count is 0

The following example:

The following is a reference fragment:
<%
Fori=1 to Request.fron ("INPUT1"). Count
Response.Write Request. From ("Input1") (I) & "<br>"
Next
%>

If the INPUT1 has two values, it shows which one is read if it is not specified with index. Available

The following is a reference fragment:
〈%
For
<% for each x in request. Form%>
Request. From (<%=x%) =<%=request. Form
(x)%> <br>
<% Next%>

12. How to obtain the client TCP/IP port:

such as: TCP/IP port is <%=request ("Server_port")%>

Use Server_port to get the connection port information for receiving HTTP request.

13. Through the Http_accept_language HTTP header information, you can get the user side of the use of the language environment.

The following example determines the locale of the client and gives a different page.

The following is a reference fragment:
<% language=request.servervariables ("Http_accept_language")
If language= "en" then%>
<!--#include file= "english.asp" >
<% Else%>
<!--#include file= "china.asp" >
<% End If%>

14. Duration of the home page retention
If the client browser browses this page again within the duration of a page retention, the page content that was originally on the user's hard drive will be displayed.

Response.expires[=number]

Where number is the retention period for the Record Data box (PAGE box), in minutes.

Or: response.expiresabsolute[=2004-10-14 7:31:25[time]]

such as: set a page retention period to a certain date.

15. Connect to the specified URL address

Such as: you want to confirm that the user has seen index.htm, you can check whether it has been seen, if not confirmed, automatically connected to the first page

The following is a reference fragment:
<%
If not session ("Been_to_home_page") Then
Response.Redirect "Index.asp"
End If
%>

16. Decide whether to return to this page or the first time to enter

The following is a reference fragment:
<%
If User_has_been_here_before Then
Response.Write "

Again
Else
Response.Write "Welcome!"
End If
%>

17. Displaying pictures in the database with super connections

The following is a reference 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 and not rs.eof%>
<tr>
<% for i=0 to Rs.fields.count-1%>
&LT;TD valign =top>
<%
If RS (i). Name= "Image" then
Response.Write " "
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
%>

18. Using ASP to get browser information

The following is a reference fragment:
<%
Set A=server.creatobject ("MSWC. BrowserType ")
Msg= "The browser you are using is:" +a.browser+ "Version" +a.version
%>
<%=msg%>

How ASP accesses cookies (using response and request)

The following is a reference fragment:
As follows: Write cookies:
Response.Cookies ("Coookies name to write")
= "Data to write"
Read cookies:
Read Data =request.cookies ("cookie name to be read")

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.