ASP for beginners!

Source: Internet
Author: User
Tags microsoft access database web database

Full write of Common acronyms and Chinese meanings

WWW ---- world wide web (World Wide Web)
URL ---- uniform resource locator (Unified Resource Locator)
HTTP ---- Hyper Text Transfer Protocol (Hypertext Transfer Protocol)
HTML ---- Hyper Text Markup Language (Hypertext Markup Language)
XML ---- eXtensible Markup Language (Extensible Markup Language)
ODBC ---- open database connectivity (Open Database Connection Standards)
DLL ---- dynamic link library (Dynamic Link Library)
Dao ---- data access objects (data connection object)
Rdo ---- Remote Data Objects (Remote Data Object)
Ado ---- Microsoft ActiveX Data Objects (Dynamic Data Object)
SQL ---- Structured Query Language (Structured Query Language)
CGI ---- Common Gateway Interface (Public Gateway Interface)
API ---- Application Programming Interface (Application Programming Interface)
ASP ---- Active Server Pages (dynamic service page)
PHP ---- personal homepage (Personal Homepage)
JSP ---- Java Server Pages
ColdFusion
SSI ---- server-side include (server-side include)
Dom ---- Document Object Model (Document Object Model)
IIS ---- Internet Information Server (Network Information Service)
IP ---- Internet Protocol (Internet Protocol)
TCP ---- Transmission Control Protocol (Transport Control Protocol)
IE ---- Internet Explorer (browser)
CSS ---- Cascading Style Sheet (stacked style sheet)
VBScript ---- Microsoft Visual BASIC script edition
ISDN-integrated business Digital Network
Web
FTP
SMTP
MMC ---- Management Console

 

 

 

 

Web design
The Web (World Wide Web) provides a graphical user interface to view documents on the Internet. These documents and their links constitute a large information network.
Originated in March 1989, Web was a master-slave distributed hypermedia system developed by the European quantum physics laboratory CERN (the ruropean Laboratory for Particle Physics.
Web is the ocean of Information Resources. The three elements ensure that people can easily travel in this ocean:
L unified resource naming scheme (URL)
L method of accessing a resource, that is, protocol (HTTP)
L free access between resources, that is, hypertext (HTTP)
With the development of Internet, web technology has gone through three stages:
L The first generation provides management and access (Display) to static documents (Information)
L The second generation, combined with the database system, provides access and display of dynamic documents (Information)
L in the third generation, in addition to dynamic document generation and access, it also provides web-based online transaction processing capabilities.
Static webpage limitations:
1. the backend database is not supported.
2. Unable to update site information in a timely manner
3. Unable to achieve dynamic display Effect
ASP is a Web application development technology launched by Microsoft at the end of 1996. ASP is neither a language nor a development tool, but an easy-to-learn and easy-to-use tool embedded in IIS/PWS, the script language can be integrated into the script language environment on the server of the HTML homepage. Its main function is to generate dynamic and interactive web server applications, providing a powerful way and technology.
ASP has the following features:
1. asp can be mixed with HTML, DHTML, Java applets, ActiveX, VBScript, and JavaScript, and can be nested with each other.
2. No compilation is required, in plain text format.
3. Good Security
4. Object-oriented
5. Scalable Server Functions
6. extensible scripting language
7. browser-independent
8. asp provides six built-in Global Objects for developers to directly call without declaration.
9. asp provides 5 important Server Components
Access the HTML page:
1. Enter the URL of the HTML file in the address bar of the client browser and press enter to send a webpage request.
2. the browser sends a webpage request to the IIS/PWS Server
3. the IIS/pwsserver receives the request and uses the extension name .htmor .html to identify the request as an HTML file.
4. the IIS/PWS server extracts the corresponding HTML file from the disk or storage and sends it back to the browser.
5. the HTML file is explained by the user's browser. The result is displayed in the browser window.
ASP Webpage access process:
1. Enter the URL of the ASP file to be requested in the address bar of the client browser, and press enter to send an ASP Request
2. the browser sends an ASP Webpage request to the IIS/PWS Server
3. the IIS/PWS server receives the request and identifies ASP files based on the extension. asp.
4. the IIS/PWS server obtains the corresponding ASP file from the disk or memory.
5. the IIS/PWS server sends the ASP file to a specific file library named ASP. dll similar to the engine.
6. the ASP. dll engine interprets ASP files from the beginning to the end, and generates corresponding dynamic HTML pages according to the command requirements in ASP files.
7. The HTML page is sent back to the client browser.
8. Use the client browser to explain and execute the HTML webpage and display the result on the client browser.
Compared with HTML, Asp has three important features:
1. asp can contain the server-side scripting language, that is, you can use dynamic content to create web pages.
2. asp uses built-in objects to make the script more powerful.
3. asp allows users to process databases, send emails, or access file systems.
Six built-in objects provided by ASP:
1. Response: send information to the browser
2. Request: used to read the request information from the browser. You can use this object to read the HTML form information.
3. SERVER: allows you to use scripts to generate instances of the active server component.
4. Application: used to store and read user-shared application information. If this object can be used to transmit shared information between different connectors on the website
5. Session: used to store and read the conversation information of a specific connector. For example, you can store the access information of the connector to the website.
6. objectcontext: used to control ASP transactions. transactions are managed by Microsoft Transaction Server (MTS ).
Five important components provided by ASP
1. Ado: used to read or store data in Microsoft SQL Server and Microsoft Access database
2. File System: provides methods and attributes for accessing computer file systems.
3. Content linking: display different HTML content based on the performance of different browsers
4. browser capabilities: Used to link different HTML pages for easier operations
5. Ad rotator: used to display banner advertisements on webpages and control the display frequency of different advertisements.
Basic ASP knowledge
The extension of ASP files is. asp, which can include HTML tags, text, and scripting languages. The script language code is included in "<% ...... Between %>.
In VBScript: Comments can be rem, ', etc.
<% Option explicit %> indicates that all variables in VBScript must be declared before they can be used. Otherwise, an error occurs.
File Inclusion: <! -- # Include file = "myfirstinc. Inc" -->
<! -- # Include file = "myfirstasp. asp" -->
<! -- # Include fileate‑myfirsttxt.txt "-->
Understand the basic usage of VBScript:
1. Operators
2. Data Type
3. constants, variables, and Arrays
4. conditional statement (if .... Then end if, if .... Then .... Else end if)
5. Loop statement (.... Next, for each .... Next, do while ..... Loop)
6. Process
7. basic functions: they can be classified into mathematics, String, date and time, type conversion, formatting, and judgment.
A) mathematics: ABS (), sqr (), RND (random number), round (rounding )...
B) string class: Len (), left (), right (), mid (), strreverse (), split (), trim ()
C) Date and Time: datevalue (), timevalue (), Year (), month, day (), hour (), minute (), second (), dateserial (), timeserial (), date (), time (), now (), datepart (), dateadd (), datediff ()...
D) type conversion class: cdate (), CINT (), clng (), CSTR (), STR (), Val (), INT (), fix ()
E) Formatting class: formatdatetime, formatnumber, formatpercent ....
F) Judgment class: isdate, isempty, isnull, isnumeric, isobject...
G) Information dialog box functions: inputbox, msgbox...
ASP built-in Object Description:
Response:
Syntax format: Response. Set | attribute | method (variable)
Response attributes include buffer, charset, contenttype, expires, expiresabsolute, status.
Response methods include addheader, appendtolog, binarywrite, clear, end, flush, redirect, and write.
Response set: cookie.
Request:
Syntax format:
Request. Set (variable)
Set: form, querystring, servervariable, Cookie, clientcertificate
1. Form: syntax format: request. Form (element) [(INDEX). Count]. <% = request. Form. Count %> Number of forms. <% = Request. Form ("name") %>
2. querystring: syntax format: request. querystring (variable) [(INDEX) |. Count]
3. servervariable: syntax format: request. servervariable (server environment variable)
4. COOKIE: syntax format: request. Cookies (cookie name) [(key) |. Attribute]
Use cookies:
Response. Cookies (cookiename) [(key) |. Attribute] = cookievalue
Request. Cookies (cookiename) [(key) |. Attribute]
Application:
Syntax format: application. Attribute | method | event | set
Application Method: Lock (), unlock ()
Application Event: application_onstart, application_onend
Set of applications: Contents and staticobjects
Application attributes: Application ("variable name") = variable name or set application ("object instance name") = Object
Global variables are defined for multiple users.
Instance name (which is restored in turn)
Session:
Syntax format: Session. Method | event | set | attribute
Session method: abandon () is used to clear the session object <% session. Abandon %>
Session event: session_onstart, session_onend
Session set: Contents and staticobjects
Session attribute: sessionid, timeout
You can also customize the session attribute, which is actually a variable, which is the session variable we mentioned earlier.
Session ("variablename") = variablename
Set SESSION ("objectname") = objectname (in turn, the variable is restored)
Lifecycle and transmission of webpage Variables
Global variables, session variables, and webpage Variables
Use the request. querystring set to pass variables between webpages
Use an ASP application or session object to pass variables between webpages.
Session and Application Comparison:
1. Both allow users to customize attributes, that is, define Application variables and session variables.
2. Both of them can be used to access the variables and object instances in the object.
3. Both have a lifecycle. When the session starts the first connection of the new connector, the connection provider does not request any information for a period of time. The application starts to run on IIS/PWS and the first connection provider appears, when no connection provider requested information or IIS/PWS was disabled for a certain period of time.
4. Both are objects shared by ASP files. The application object is an object shared by all web page connectors, and the session object is unique to each connector.
5. Both have onstart and onend event codes, but they occur at different times. When an application and a session application are started at the same time, ASP will first execute application_onstart and then execute session_onstart. If the application program ends at the end of a session, session_onend is executed before application_onend is executed.
Global. Asa file and application initialization:
Global. Asa file:
Website counters or online statistics
Server Object, ODBC, and ADO components:
Server syntax format: Server. Attribute | Method
Server attribute: scripttimeout
Server method: Createobject, htmlencode, urlencode, mappath
The Createobject method of server is the most practical and powerful function in ASP. It can create ActiveX component instances registered on the server and is the source of ActiveX objects.
Server. Createobject ("component name or component Registration Name ")
Set myconn = server. Createobject ("ADODB. Connection") to connect to the object instance
Set myads = server. Createobject ("mswc. adrotator") Advertisement object instance
ODBC: a common interface for connecting to databases. It is a database connection standard developed and advocated by Microsoft.
ADO is a very important component built-in component of ASP server and web database operations.
The ADO component is a powerful component consisting of seven interface components, respectively:
1. Connection component
2. recordset component
3. Command component
4. Parameter object
5. porperty object
6. Error object
7. Field object
The first three components must be created using the server. Createobject method before they can be used.
Connection: syntax format: Set connection object name = server. Createobject ("ADODB. Connection ")
For example, set conn = server. Createobject ("ADODB. Connection ")
Method of the connection object:
1. Open format: connection object name. Open "Connection database information string" [; user account] [; User Password]. This method is used to open a database and establish a connection with it. There are two methods:
A) Open the database using the DSN method: This method first uses ODBC to create the data source name (DSN) of the corresponding database, and then opens the corresponding database using the data source name. The following code opens the database book. mdb corresponding to the data source name qhbook. <% Set conn = server. Createobject ("ADODB. Connection") Conn. Open "qhbook; mydata; zhxing" %>
B) Open the database using the full path DSN method. If no ODBC data source is established before connecting to the database, you can also directly specify the ODBC driver name to establish a connection to the database. In this case, the "Connection database information string" must start with the driver and change to "driver = {ODBC driver name}; DBQ =" & server. mappath ("Database Name:
<% Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("book. mdb") %>
For SQL Server, the driver is driver = {SQL Server}; for Oracle, driver = {Microsoft ODBC for Oracle }.
2. Close: close a established connection object and its related objects. <% Conn. Close %> <% set conn = nothing %>
3. Execute:
Format 1: connection object name. Execute (SQL command ).
Format 2: connection object name. Execute (data table name ).
As follows:
<% SQL = "select * From bookitem" set rs = conn. Execute (SQL) %> or:
<% Set rs = conn. Execute ("bookitem") %>
4. begintrans
5. committrans
6. rollbacktrans
Recordset component:
Conn. the open method knowledge opens and connects to the corresponding database. The database is usually composed of one or more tables. Therefore, to access the data table, you must create a recordset object, in order to perform various operations on it.
1. Create A recordset object
The methods are as follows:
Set recordset object name = server. Createobject ("ADODB. recordset ")
Set recordset object name = connection. Execute ("data table name ")
Set recordset object name = connection. Execute (SQL command)
The following code:
<%
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "qhbook; mydata; zhxing"
Set rs = conn. Execute ("bookitem ")
%> Or
<%
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("book. mdb ")
Set rs = server. Createobject ("ADODB. recordset ")
Exec = select * From bookitem
Rs. Open exec, Conn
%>
Method of recordset object:
Open: Format 1: Rs. Open exec, Conn, (record set type (,), lock type ))
Format 2: Rs. Open bookitem, Conn, 1, 1
Recordset type: 0: Read-only. The current data record can only be moved downward.
1: Read-only. The current data record can be moved freely.
2: read/write. The current data record can be moved freely.
3: read/write, and the current data record can be moved freely (note)
Lock type: 1: Default Value, used to open read-only data records
2: Pessimistic locking
3: Optimistic Locking
4: Optimistic batch locking
Close Method
<% Rs. Close
Set rs = nothing %>
How to move the recordset Object Pointer:
Movefirst
Movelast
Movenext
Moveprevious
Move numrecords, start:
Operation Method of the recordset object:
Addnew: This method can add a record to the recordset object.
Delete: delete a record in the recordset object.
Update: updates the current record of the recordset object.
Cancelupdate: cancels the update and is valid only after the update method.
Updatebatch: When the lock type is 4, this method is used to save modifications to one or more records.
Recordset Object Attributes
Absolutepage
Absoluteposition
Activeconncetion
BOF
EOF
Bookmark
Cachesize
Cursorlocation
Cursortype
Editmode
Filter
Locktype
Maxrecords
Pagecount
Pagesize
Recordcount
State
Source
Field object and set
Field attribute:
Name, value, type ,....
Field Method: AppendChunk, getchunk
Field set:
Output Data Table header:
For I = 0 to Rs. Fields. Count-1
Response. Write "<TD>" & Rs. Fields (I). Name & "</TD>" (note: the number of elements obtained from the form is similar to this. Request. Form. Count)
Next
Values of each record in the output table:
For I = 0 to Rs. Fields. Count-1
Response. Write "<TD>" & Rs. Fields (I). Value & "</TD>"
Next
Use ADO and SQL to query Databases
Create a database and a data source:
In this example, Microsoft Access 2000 is used to create a library management database named book. mdb, where the data table is bookitem and there is only one table.
Structure of the bookitem table:
Book_id (number): long integer, primary key
Book_name, book_author, book_price (currency), book_press, book_date (date)
The DSN used to create the database is named qhbook. The account and password are Internet.
Select All records using select:
Format: select [Top N] field list from data table name (* indicates all fields, separated by multiple fields)
1. Select * From bookitem
2. Select book_name, book_author, book_price from bookitem
3. Select * From bookitem where book_name = 'lonely goat'
Select * From bookitem where book_name like '% principle %' (wildcard % and _, where % represents any number, and _ represents one .)
Select * From bookitem where book_price between 20.00 and 23.00
Select * From bookitem where book_price> = 20.00 and book_price <= 23.00
Select * From bookitem where book_price between 12.00 and 20.00 and book_name like '% System %'
Select * From bookitem where book_date >=# 2000/3/1 # And book_name like '% principle %'
The conditional expressions after where can use logic, comparison, like,... And, in/Not, In, isnull/is not null and other operators to form a variety of filtering.
Select [Top N] field list from data table name where condition expression
4. Select [Top N] field list from data table name where condition expression order by field list [DESC] in descending order:
Select * From bookitem order by book_date DESC, book_price DESC
Select * From bookitem where book_date >=# 2000/3/1 # order by book_name
Select Top 4 * From bookitem where book_date >=# 2000/3/1 #
Insert record:
Format 1: insert into data table name [(field name list)] values (Field Value List)
Format 2: Rs. Open SQL, Conn, 2, 3
Addnew
Assign values to Fields
Update (this method is most commonly used, especially when combined with forms, adding records through forms)
For example:
Insert into bookitem (book_name, book_author, book_price) values ('title ', 'author', 'price ')
Delete record:
Format 1: Delete from data table name where condition expression (delete in SQL)
Format 2: Rs. Open SQL, Conn, 2, 3 (record set deletion method)
Rs. movelast
Rs. Delete
Rs. Update (a common method)
For example, delete from bookitem where book_author = 'width'
Modification record:
Rs. Open SQL, Conn, 3, 3
Rs. movelast
RS ("book_author") = "author"
Rs. Update
 
 

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.