Using ASP development web applications

zhaozj2021-02-11  213

Using ASP development web applications

Typically, users who see from the browser are mostly static, and with the development of the web application, users want to see the home page that is generated as required, such as responding to the user querying the requirements of the database, generating reports, etc.

The traditional methods of generating dynamic homepages are cgi, isapi, etc. according to user requests to generate dynamic homepages. CGI is based on the HTTP request to activate the response process according to the HTTP of the browser, and each request corresponds to a process. When there are many requests, the program crowds system resources, resulting in low efficiency; ISAPI is improved for this shortcoming, using DLL (dynamic link library) technology to thread replace the process, improve performance and speed, but consider synchronization of threads Problem, and development steps are cumbersome. There are still another problem with the development of developing dynamic webpages in the development of the two technologies and the other universal use. It is the development difficult, the development of the program is two completely different processes, and special programmers are required. More simple development technologies such as the limited functions such as JavaSC RIPT and IDC (Internet Database Connector), not for use.

ASP is ActiveX Server Page, which is a new generation of developed dynamic web pages of Microsoft. It has its own advantages of simple development, powerful and powerful, which can be very intuitively and simple to achieve complex web applications. This article will introduce the basic concepts, features, development factors of the ASP, and introduce specific implementations using the ASP development web application by two typical examples.

ASP concept and workflow

ASP is a web server-side development environment that uses it produces and runs dynamic, interactive, high-performance web service applications.

ASP is a Server-end technology in ActiveX technology. Similar techniques such as JA VA Applet, ActiveX Control, VB Script, JavaScript, etc. in the Client side are different, and the commands and Script statements in the ASP are interpreted by the server, and the execution result generates a dynamically generated web page. And send it to the browser; and the script command of the Client end technology is explained by the browser. Since the ASP is performed on the server-side interpretation, the developer can not consider whether the browser supports the ASP; at the same time, due to the execution of the server, developers don't have to worry about the order of the program to steal programming logic.

ASP is implemented by an ASP file named .asp, an ASP file is equivalent to an executable file, so it must be placed in a directory of executable permissions on the web server.

When the browser requests to call the ASP file to the web server, the ASP is activated. Web Server starts calling the ASP, read the requested .asp file from the bottom, executes each command, and then dynamically generates an HTML page and sent to the browser. The ASP file is made and HTML is similar, and it is integrated with HTML, which can be done in the same process. With an ASP built-in object, server components can complete a very complex task, and users can develop or use others to develop a dedicated task.

ASP has the following features:

Complete and HTML integration;

Easy to generate, no need to compile and connect;

Object-oriented, can extend ActiveX Server components.

The current ASP is only available for the following Web Server:

IIS 3.0 on windows NT;

Microsoft Peer Web Server V3.0 on NT Workstation;

Microsoft Personal Web Server On Win95.

ASP file

1.ASP file production

The ASP file is a file that is the .asp, is a text file that can include any combination of the following elements: Text (Text)

HTML Sign (Tags)

Script command

Making ASP files is very simple, you can use any form of formatted text editing tool (I always use NOTEPAD), or you can use a special home development tool and ASP development tool such as Visual inetdev. Please see the example below:

Time: <% = no%> Make it a buffet for .asp file, put it in a directory specified by the Web Server, and then outputs the current time of the server. Note: The ASP file cannot be executed by open, but must be a link, for example, assume that the ASP is a virtual directory with execution permissions on the web server (hostname host). To perform Hello.asp in this directory, call The way should be:

http://host/asp/hello.asp

2.asp grammar

ASP is not a language, it just provides an environment to run Script in the ASP file. In order to use AS P to take ASP, the grammar rules of the ASP must be observed. The syntax of the ASP consists of several elements below:

Delimiter

The delimiter is used to define a symbol of a flag unit such as "<" and ">" in HTML.

Similarly, the command and output expression of the ASP Script also have a delimiter, which is different from TEXT and HTML, and its command delimiter is "<%" and "%>". For example, the following is an assignment statement:

<% Name = "Timeout"%>

ASP uses "<%" = and "%>" to output expressions to the browser, for example:

<% = Name%> will output "timeout" on the browser.

Script logo

ASP can use any script language, as long as the corresponding script driver is available, the ASP itself provides the driver of VBScript and JScript. Its default Script language is VBScript, of course, developers can also change this default setting, for example to change to JScript, just indicate <% @ language = jscript%> in the file. The part of and is to describe the language program, similar to HTML. Different is that this part is performed by the browser in HTML, but is executed by the web server in ASP.

You can use several different script languages ​​in one .asp file, just enclose each paragraph to enclose each parameter> and to be enclosed in and . You can also include Script executed in the browser side, release the description statement, and the program is explained by the browser.

HTML tag:

Various expressions in the HTML language can be included in the ASP file.

ASP built-in object

The ASP provides five built-in objects to provide a higher level of web features, which are:

Request: Get information from the user;

Response: Give the user to the user; Server: Provides the web server tool;

Session: Information stored in a session within a session;

Application: Make different users in an ASP application.

The most used is the top three objects. Request and Response are used to implement Web Server and browser interactions. One important way to r equest is Form (), which is the user input information for extracting the browser. For example, there is a text edit box in the home page, which has specified its variable name "name", form's action is an ASP file. The following statement can get the content of the user to fill in it:

Request.form ("Name")

Obviously, this avoids complex programming required in CGI and other methods.

Output an important way to use the RESPONSE WRITE:

Response.write "Your Message"

This statement outputs a message to the user browser.

There are two important ways for Server objects: mappath and createObject. Mappath is used to restore the virtual path of Web Server to the actual path; CreateObject may be the most important method to generate analog instance of server components, detail, detail.

Server component

Dynamic web pages can be easily generated by Script and HTML of the server, but the function is limited, such as the server database, using a network function or access server file system. In order to solve this problem, it is necessary to use CO M technology, which is Component Object Model. Almost all ActiveX technology is based on this. It is easy to use other COM components through COM, which is a server component. A server component uses server resources for a considerable object, providing properties, and methods. The server component can be developed by any third party supporting Active X, and the ASP itself has five server components, which can be used directly, and can complete the work of most of the server.

To call server components, you must first use the method of the method CreateObject in the Server object to generate an instance of the server component object, as shown below:

Server.createObject (ProgID)

Here, the PROGID specifies the component identification, and the component can be a variety of forms of executable programs (DLL, EXE, etc.), and it is not necessary to consider its location, as long as you register for these programs in Windows NT (or 95), COM will These materials are maintained in the system database, while making programmers in a Progid mode. Register with Regsvr32 programs to see ProgID with regedit programs. Once the component is generated, it can work with its method and attribute.

The segment of the general use of the Server component is as follows:

'Generating components

SETOBJ = Server.createObject ("progID")

'Using it

Obj.method

The ASP provides five server components, the most important two are database access components AdoDB and file access components f iLesystemObject, and the examples of this article will explain their use.

For some special needs, developers can also develop server components themselves, using VB or VC, which can easily open some components, then register these components, you can call with server.createObject. There are also many sites with a well-developed component for download, as long as they can register them on their own machines. ASP application instance

1. Use the file access component to make the home page Access Counter

Now there is a counter on many homepages to record the number of times the home page is accessed, usually the counter is implemented through the CGI, and the development process is more complicated. Some non-professional programmers are difficult to implement. A counter can be easily produced by ASP's file access component file accepting.filesystemObject. Here is an example, its principle is: Generate a count file according to Page Hits, read the numbers in the count file, and then dynamically adjust the images of 1, 2, and 3. Its basic procedure and CGI are similar, but when sending an image, the CGI is dynamically generated through the program, and our method is to transfer the image existing in the machine, so that Making a very beautiful digital image. Its program fragment is:

<%

Countfile = Server.mappath ("/ gjy" "/ count.txt")

'Count file

Set fileobj = server.createObject ("scripting.filesystemObject") "Generates file access components

Set out = fileobj.opentextfile (countfile, 1, false, false) Opens the file

Visitors = out.readline 'reads an access record

Visitors = Visitors 1 'plus one

LENGTH = LEN (Visitors) 'The number of images called

Strurl = "" "URL of the image

Do While Length> = 1

Strurl = "" Strulll

Length = Length-1

LOOP 'Generate Image URL

Set out = fileObject.createtextfile (countfile, true, true)

Out.writeline (Visitors) 'record number

%>

<% = Strurl%> 'output image

Note: The reader can set the image file path according to the situation of the server.

2. Access the server database with Data Access Component (AdoDB .connection)

Let users query the backend database through the browser's back-end database is the required services that many web service providers, and the ASP implements this feature through the built-in AdoDB components. ADO is Active Data Object, like DAO, and RDO, which belongs to the COM components of the database applications. Different, ADO is developed specifically for Internet and Web and optimizes this. The steps to use the ADO query database are:

 Set DSN

The AdoDB works through the ODBC, so set the DSN (data source name) in ODBC.

Generate an instance of an ADODB component

SET Connect = Server.createObject ("AdoDb.Connection") Connect Database

Use the ADODB member function Open and previously set DSN and database connections:

Connect.open ("DSN = DSNNAME; UID = UserId; PWD = Password")

Execute query

Specify SQL query statement:

SQL = SELECT * from TableName

Executive query:

SET RS = Connect.execute (SQL)

 结果 结果

Complete program fragment:

<%

SET Connect = Server.createObject ("AdoDB. Connection") "Generates Components Instance

Connect.Open ("DSN = DSNNAME; UID = UserID; PWD = Password") 'connection database

SQL = SELECT * from TableName

SET RS = Connect.execute (SQL) 'Execute Query

%>

<% Do while not rs.eof%> 'display result

<% = Rs (fieldname)%>

<%

Rs.movenext

Loop

%> Conclusions ASP is simple and intuitive, and the development process can be conveniently integrated with HTML; using COM technology, it can also achieve more and more complex functions.

转载请注明原文地址:https://www.9cbs.com/read-4111.html

New Post(0)