ASP Beginners Reference

Source: Internet
Author: User
Tags expression file system odbc object model one table variables string table name
Reference | Beginners Common acronyms and Chinese meanings

WWW----World Wide web (WWW)
URL----Uniform Resource Locator (Uniform 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 DB connectivity (Open Database Connectivity standard)
DLL----Dynamic Link library
DAO----Data Access Objects (Connection object)
RDO----Remote Data Objects
ADO----Microsoft ActiveX data Objects (Dynamic object)
SQL----Structured Query Language (structured queries language)
CGI----Common Gateway Interface (Public Gateway Interface)
API----Application Programming Interface (Application programming Interface)
ASP----Active Server Pages (Dynamic services page)
PHP----Personal Homepage (personal homepage)
JSP----Java Server Pages
ColdFusion
SSI----server-side include (server-side included)
DOM----Document Object model
IIS----Internet Information Server (Network information Services)
IP----Internet Protocol (Internetwork Protocol)
TCP----Transmission Control Protocol (Transmission Control Protocol)
IE----Internet Explorer (browser)
CSS----Cascading style Sheet (cascading style sheet)
VBScript----Microsoft Visual Basic Script Edition
ISDN----Integrated Services Digital Network
Web
Ftp
Smtp
MMC----Management Console










Web Design before
The Web (WWW) provides a graphical user interface that browses documents on the Internet and the links between them constitute a vast network of information.
The web originated in March 1989 and was developed by the European Quantum Physics laboratory CERN (the Ruropean Laboratory for particle physics) as a master-slave structure distribution hypermedia system.
The web is the ocean of information resources, three elements ensure that people can easily travel in this ocean:
• Unified resource naming scheme (URL)
L access a resource in a way that is protocol (HTTP)
• A method of free access between resources, i.e. hypertext (HTTP)
With the development of the Internet, Web technology has gone through 3 stages of development:
L first generation, providing management and access to static documents (information) (display)
L second generation, combined with database systems, provides access to and display of dynamic documents (information)
Third generation, in addition to dynamic document generation and access, also provides web-based online transaction processing capabilities.
Lack of static web pages:
1. Unable to support background database
2. Unable to effectively update the site information in a timely manner
3. Can not achieve dynamic display effect
ASP is a server-side Web application development technology that Microsoft launched at the end of 1996. ASP is not a language, nor a development tool, but an easy to use embedded in the IIS/PWS, can integrate the script language to the HTML homepage of the server side of the scripting language environment, its main function is to generate dynamic, Interactive Web server applications provide a powerful way and technology.
The features of ASP are as follows:
1. ASP can mix Html,dhtml,java applet, Activex,vbscript,javascript, and can nest each other.
2. Do not need to compile, plain text format.
3. Good safety
4. Object-oriented
5. Extensible server-side functionality
6. Extensible Scripting language
7. Browser-Independent
8. ASP provides 6 built-in global objects for developers to call directly without requiring a declaration
9. ASP provides 5 important server components
The process of accessing an HTML page:
1. Enter the URL of the HTML file at the address bar of the client browser and press ENTER to send a Web request
2. Browser send Web page request to IIS/PWS server
3. The IIS/PWS server receives a request that is an HTML file by using the extension. htm or. html.
4. The IIS/PWS server takes the corresponding HTML file out of the disk or storage and sends it back to the browser
5. html files are interpreted by the user's browser and the results are displayed in the browser window
Procedures for accessing ASP Web pages:
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. Browser sends ASP Web page request to IIS/PWS server
3. The IIS/PWS server receives the request and recognizes the ASP file according to the extension. asp
4. The IIS/PWS server obtains the corresponding ASP file from the disk or the memory
5. The IIS/PWS server sends an ASP file to a particular file library, named Asp.dll, similar to the engine engine
6. The Asp.dll engine interprets the ASP file from beginning to the beginning, and generates the corresponding dynamic HTML page according to the command request in ASP file
7. HTML page is sent back to the client browser
8. Interpret the execution of HTML Web pages with client browsers and display the results on the client browser
ASP has 3 important features compared to HTML:
1. asp can contain server-side scripting language, that is, you can create Web pages with dynamic content
2. ASP uses built-in objects to make scripting more powerful
3. ASP uses the component to enable the user to process the database, sends the email or accesses the file system and so on
6 built-in objects provided by ASP:
1. Response: Send message to Browser
2. Request: Used to read requests from the browser, you can use this object to read information about HTML forms
3. Server: Allow scripts to generate an instance of an active Server component
4. Application: Used to store, read user-shared application information, such as the use of this object in the site to communicate between different connectors to share information
5. Session: Used to store, read the conversation information of a particular connector, such as to store the connection's access information to the site
6. ObjectContext: For controlling ASP transactions (Transaction), transactions are managed by Microsoft Transaction Server (MTS)
5 Important components provided by ASP
1. ADO: Used to read or store data in a Microsoft SQL server,microsoft Access database
2. File system: Provides methods and properties that you can use to access your computer's file system
3. Content Linking: Display different HTML content depending on the performance of different browsers
4. Browser capabilities: Used to link different HTML pages to make it easier to operate
5. Ad Rotator: Used to display banner ads on the Web page, and to control the display frequency of different ads
Basic knowledge of ASP
The ASP file has an. asp extension, which can include HTML markup, text, and scripting languages, with scripting language code included between "%......%>".
In VBScript: Annotations can be REM, ' etc.
% Option Explicit%> indicates that variables in VBScript are declared before they can be used, otherwise there will be an error.
File contains:!--#include file= "Myfirstinc.inc"-->
!--#include file= "myfirstasp.asp"-->
!--#include file= "Myfirsttxt.txt"-->
Understand the basic usage of VBScript scripts:
1. Operator
2. Data type
3. Constants, variables, and arrays
4. Conditional statement (If....then End If, If....then....else End If)
5. Loop statement (For....next, for Each....next, do While.....loop)
6. Process
7. Basic functions: Divided into mathematical class, String class, Date time class, type conversion class, format class and judgment class.
A) Math class: ABS (), SQR (), RND (random number), round (rounded) ...
b) String class: Len (), left (), right (), Mid (), StrReverse (), Split (), Trim ()
c) Date-time classes: 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) format class: Formatdatetime,formatnumber,formatpercent ....
f) Judgment class: Isdate,isempty,isnull,isnumeric,isobject ...
g) Information dialog box function: Inputbox,msgbox ...
ASP Built-in Object Description:
Response:
Syntax format: Response. Collection | properties | Method (Variable)
The response properties are: Buffer,charset,contenttype,expires,expiresabsolute,status.
The response methods are: Addheader,appendtolog,binarywrite,clear,end,flush,redirect,write
Collection of response: cookies.
Request:
Syntax format:
Request. Collection (variable)
Collection: Form,querystring,servervariable,cookie,clientcertificate
1. Form: Syntax format: request.form (Element) [(index). Count]. %=request.form.count%> a single number of tables. %=request.form ("name")%>
2. QueryString: Grammatical 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 Collection:
Response.Cookies (CookieName) [(Key) |. Attribute]=cookievalue
Request.Cookies (CookieName) [(Key) |. Attribute
Application:
Syntax format: Application. Properties | methods | events | collection
Application method: Lock (), UnLock ()
Application Events: Application_onstart,application_onend
Collection of application: contents,staticobjects
Application properties: Application ("variable name") = variable name or Set application ("object instance name") = Object
In fact, we define global variables for use by multiple users.
Instance name (conversely, restore)
Session:
Syntax format: Session. Method | events | collection | properties
Session method: Abandon () is used to clear the Session object% Session.Abandon%>
Session Event: Session_onstart,session_onend
Session Collection: Contents,staticobjects
Session Properties: Sessionid,timeout
The user can also customize the session attribute, which is actually a variable, which is the conversation variable we talked about earlier.
Session ("VariableName") =variablename
Set session ("objectname") =objectname (reverse is the restore variable)
Life cycle and delivery of web variables
Global variables, session variables, web variables
Passing variables between pages with the Request.QueryString collection
Pass variables between pages using an ASP's application or Session object.
Comparison of Session and application:
1. Both allow users to customize attributes, that is, to define application variables and session variables.
2. Both can be used to access variables and object instances in the object
3. Both have a life cycle. The session begins when the new connector first connects, terminating the connection for a period of time without any information being requested; application begins when IIS/PWS starts executing and the first connector appears, terminating for a certain period of time without any of the connectors requesting information, or iis/ When the PWS is closed.
4. Both are objects that are shared by ASP files. The Application object is an object that is shared by all Web-page connectors, and the session object is an object unique to each connector.
5. Both have OnStart and OnEnd event codes, but they occur at different times. When a application application starts at the same time as a session application, the ASP executes the Application_OnStart before executing the Session_OnStart; If you end the application application at the end of a session, the Session_OnEnd is executed before the Application_OnEnd is executed.
Global.asa file and application initialization:
Global.asa file:
Website counter or statistics online numbers etc
Server objects, ODBC, and ADO components:
Server syntax format: Server. Properties | method
Server properties: ScriptTimeout
Server method: Createobject,htmlencode,urlencode,mappath
The CreateObject method of the server is the most useful and powerful feature in ASP, which creates an ActiveX component instance that has been registered to the server and is the source of the ActiveX object creation.
Server.CreateObject ("Component name or component registration name")
Set myconn=server.createobject ("adodb.connection") Connection object instance
Set myads=server.createobject ("MSWC. AdRotator ") Ad object instance
ODBC: is a common interface for connecting to databases, a standard for database connectivity developed and promoted by Microsoft companies.
ADO: is an ASP server built-in components and implementation of the Web database operation is a very important component.
The ADO component is a powerful component that consists of 7 interface components, as follows:
1. Connection components
2. Recordset Components
3. Command component
4. Parameter Object
5. Porperty Object
6. Error Object
7. Field Object
The first three components need to be built using the Server.CreateObject method.
Connection: Syntax format: Set Connection object name =server.createobject ("ADODB. Connection ")
such as: Set Conn=server.createobject ("ADODB. Connection ")
Ways to Connection objects:
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 ways of doing this:
A to open the database using the DSN method: The method first establishes the data source name (DSN) of the corresponding database with ODBC, and then opens the corresponding database through 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 Use the full path DSN method to open the database. If you do not establish an ODBC data source before you connect to the database, you can also establish a connection to the database by using a method that specifies the ODBC driver name directly. The "Connection database information string" At this point must start with Driver and become "DRIVER={ODBC driver name};d bq=" &server.mappath ("Database name"). as follows:
% Set conn=server.createobject ("ADODB.") Connection ")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Book.mdb")%>
If it is a SQL Server type, the driver is Driver={sql Server}; If it is an Oracle type, then: Driver={microsoft ODBC for Oracle}.
2. Close: Closes an already established connection object and its associated objects. % conn.close%>%set conn=nothing%>
3. Execute:
Format One: Connection object name. Execute (SQL instruction).
Format Two: 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:
The previous Conn.Open method knowledge opens and connects to the corresponding database, which is usually made up of one or more tables, so the Recordset object must be created to access the data table before it can be manipulated.
1. Creating a Recordset object
The methods are as follows:
The Set Recordset object name =server.createobject ("ADODB. Recordset ")
Set Recordset object name =connection.execute ("Datasheet name")
Set Recordset object name =connection.execute (SQL instruction)
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)};d bq=" &server.mappath ("Book.mdb")
Set rs=server.createobject ("ADODB. Recordset ")
Exec=select * from Bookitem
Rs.Open Exec,conn
%>
Method of the Recordset object:
Open: Format one: Rs. Open exec,conn,1,1 (recordset type (0,1,2,3), lock type (1,2,3,4))
Format two: Rs. Open bookitem,conn,1,1
Recordset Type: 0: Read only, current data record can only move Down
1: Read only, the current data record can move freely
2: Can read and write, the current data record can move freely
3: Can read and write, the current data record can move freely (note)
Lock type: 1: Default value to open read-only data records
2: Pessimistic lock
3: Optimistic Lock
4: Batch Optimistic lock
Close method
% Rs. Close
Set rs=nothing%>
How the Recordset object pointer moves:
MoveFirst
MoveLast
MoveNext
MovePrevious
Move Numrecords,start:
How the Recordset object is manipulated:
Addnew: This method can add a record to the Recordset object
Delete: Deletes a record from a Recordset object
Update: Updating the current record of a Recordset object
CancelUpdate: Cancel the update until the method is updated
UpdateBatch: When the lock type is 4 o'clock, this method is used to save changes to one or more records.
Properties of the Recordset object
AbsolutePage
AbsolutePosition
Activeconncetion
BOF
Eof
Bookmark
CacheSize
CursorLocation
CursorType
EditMode
Filter
LockType
MaxRecords
PageCount
PageSize
RecordCount
State
Source
Field objects and collections
Field attribute:
Name,value,type,....
Field method: Appendchunk,getchunk
Field collection:
Output data table header:
For I=0 to Rs.fields.count-1
Response.Write "Td>" &rs.fields (i) .name& "/td>" (note: The previous one has the number of elements to get form, similar to this. Request.form.count)
Next
Values for each record in the output table:
For I=0 to Rs.fields.count-1
Response.Write "Td>" &rs.fields (i) .value& "/td>"
Next
Query database with ADO and SQL
To establish a database and data source:
This example uses Microsoft Access 2000 to create a library management database named Book.mdb, where the datasheet is Bookitem and has only one table.
Structure of the Bookitem table:
book_id (numbering): Long plastic, primary key
Book_name,book_author,book_price (currency), book_press,book_date (date)
The DSN that establishes this database, name Qhbook, account number and password are: Internet
Select All records with select:
Format: Select [top N] Field list from Datasheet name (* represents all fields, multiple fields, separated)
1. Select * FROM Bookitem
2. Select Book_name,book_author,book_price from Bookitem
3. Select * from Bookitem where book_name= ' lonely sheep '
Select * from Bookitem where book_name like '% principle% ' (wildcard% and _, where% represents any number, _ 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 the principle% of/3/1# and book_name like '% '
The conditional expression after the where can be composed of various filters using the logical, comparative, like,between...and,in/not,in,isnull/is not NULL operators.
Select [Top N] field list from data table name Where condition expression
4. Select [Top N] Field list from datasheet name Where conditional expression order by field list [Desc] 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 one: Insert into datasheet name [(field list)] Values (List of field values)
Format two: Rs. Open sql,conn,2,3
Addnew
Assign values to each field
Update (This method is most commonly used, especially when combined with a form, to add records through a form)
Such as:
Insert into Bookitem (book_name,book_author,book_price) Values (' title ', ' Author ', ' Price ')
To delete a record:
Format one: Delete from data table name Where condition expression (SQL language deletion)
Format two: Rs. Open sql,conn,2,3 (Delete method of Recordset)
Rs. MoveLast
Rs. Delete
Rs. Update (one of the common methods)
such as: Delete from Bookitem where book_author= ' i '
To modify a record:
Rs. Open sql,conn,3,3
Rs. MoveLast
RS ("book_author") = "I"
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.