Sie sind auf Seite 1von 16

GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY

END TERM EXAMINATION 2011 STUDY MATERIAL COURSE: BBA (CAM) Unit: II (Introduction to Active Server Pages)

Subject: Web Designing and Development PART B: [Introduction to Active Server Pages] 1. Introduction to Active Server Pages:
Active Server Pages (ASP) is a server-side scripting technology that can be used to create dynamic and interactive Web applications. An ASP page is an HTML page that contains serverside scripts that are processed by the Web server before being sent to the user's browser. You can combine ASP with Extensible Markup Language (XML), Component Object Model (COM), and Hypertext Markup Language (HTML) to create powerful interactive Web sites. Active Server Pages (ASP) is a Microsoft technology that allows webmasters to create dynamic content. ASP is not a stand-alone programming language. An ASP script uses JavaScript or Visual Basic scripting language to generate dynamic pages on the server side. Active Server Pages were introduced by Microsoft in 1996 as a downloadable feature of Internet Information Server 3.0. The concept is pretty simple: an Active Server Page allows code written in the JavaScript or VBScript languages to be embedded within the HTML tags of a Web page and executed on the Web server. There are great advantages to this, not the least of which is security. Since your code is executed on the Web server, only HTML tags are sent to the browser. The result is that the ASP code is invisible to the end user.

Server-side scripts run when a browser requests an .asp file from the Web server. ASP is called by the Web server, which processes the requested file from top to bottom and executes any script commands. It then formats a standard Web page and sends it to the browser.

It is possible to extend your ASP scripts using COM components and XML. COM extends your scripting capabilities by providing a compact, reusable, and secure means of gaining access to information. You can call components from any script or programming language that supports Automation. XML is a meta-markup language that provides a format to describe structured data by using a set of tags.

2. Meaning of Active Server Page:


Active Server Pages (ASP) is a server side scripting language that lets a webmaster transform the plain, static web site into a dazzling, dynamic solution. With Microsoft's server side scripting language you can gather data from your site's visitors, use sessions, cookies, application variables, and more. Active Server Pages (ASP) is a "server-side" scripting environment that you can use to create and run dynamic, interactive Web server applications. With ASP, you can combine HTML pages, script commands, and COM components (including ActiveX controls) to create interactive Web pages or powerful Web-based applications, which are easy to develop and modify. The requirement of embedding ASP code into your web sites HTML Pages is inevitable to fulfill the need of a dynamic data-driven web site. The most impressive fact about the web site developed using ASP is that they change as per the actions of the user. It is through the ASP code that you get to link your web pages to a database so that interaction with the web page by logging in can be accomplished.

3. Difference between HTML and ASP:


With conventional static HTML, the user types in a Web address and the browser sends a request for the Web page to a Web server. The Web server receives the request and retrieves the appropriate HTML file from a disk or memory and transmits it back to the browser. The user's Web browser translates the HTML file and the results are displayed in the browser window. The results are static as long as the underlying HTML page is unchanged. Static Web pages are used when information is not expected to change much over time. Static Web pages are ideal for home pages or sites where content is not going to be modified frequently. In order to make changes to static Web pages, one must edit the HTML file.

ASP and conventional HTML work in almost the same way. One major difference between ASP and conventional HTML is that ASP is dynamic. This is because with ASP, scripting code runs on the server and produces HTML output, which is then sent to the browser for display. When a browser requests an ASP file from the Web server, the ASP interpreter reads through the ASP file, executes any of the ASP commands contained within and sends the resulting HTML to the browser. This means that the same ASP page might produce HTML that appears in the browser differently each time it is requested. An ASP file can contain any combination of HTML and script. Since ASP pages produce standard HTML, they require no specific browser.

4. Applications/ Uses of Active Server Pages:


Following are the applications of Active Server pages:

Dynamically edit, change, or add any content of a Web page Respond to user queries or data submitted from HTML forms Access any data or databases and return the results to a browser Customize a Web page to make it more useful for individual users The advantages of using ASP instead of CGI and Perl, are those of simplicity and speed Provide security - since ASP code cannot be viewed from the browser Clever ASP programming can minimize the network traffic

5. Advantages and Disadvantages of Active Server Pages: Advantages of ASP


1. Performance: ASP.NET improves performance by utilizing the strengths of JIT compilation, automatic resource optimization, runtime profiling, automatic memory management, early binding, better caching and exception handling.

2. Inbuilt data caching module: ASP.NET has a data caching module to decide on which data on the ASP page should be cached and when to empty this cache and when to re-query.

3. Support for Tools: With ASP you can drag and drop your web controls just like how it is done in Visual Basic controls. All you have to do is just double click to write a server program for the control. 4. Ease of Use: ASP pages are just HTML pages with ASP programs encapsulated between <% and %> tags. To run an asp file you just have to place it into a directory in your server and run it provide you have proper authorization. All you have to do to make some changes is just edit your asp file and the modification will be executed. 5. Flexibility: With ASP you can code your scripts in both VBScript and Microsoft Jscript. There are also existing modules to support languages like Python, perl along with solutions to incorporate other languages. So even if you are new to ASP you can use your previous knowledge in other programming languages like VB and JavaScript while migrating to ASP. This makes it easier to learn ASP even with just html knowledge.

Disadvantages of ASP
1. Higher costs: To process asp pages you need to install IIS on a Windows platform server. You have to buy MS-SQL to connect to your database in ASP. And you need to add some components as there are no inbuilt features like in PHP. All these activities will cost you money. 2. Lower Speed: ASP is slower than PHP, as it is based on COM architecture that is actually an overhead to the server. 3. Not Platform Compatible: ASP does not have platform compatibility like PHP. This is because it is mostly dependent on Microsoft products and needs a Windows platform along with an ASP-Apache installation at the server side. 4. Needs VB knowledge: The syntax of ASP has a lot of similarity with that of Visual Basic. Hence some VB knowledge is needed to program is ASP.

Therefore, ASP is one of the best options for e-business software development. At the same time we cannot rule out the other languages completely as they have their own advantages.

6. Functions and Features of Active Server Pages:


1. Active Server Pages or ASP is one of the most familiar and commonly known technologies in the IT world. It is a server side technology which is used to display dynamic content on web pages. Active Server Pages was initially launched and established by Microsoft on its web server. It is possible to write code using ASP, which could provide your visitors with unique information, different images and even a totally different page depending upon the kind of browser version used. ASP can be used along with various scripting languages such as Perl Script or J Script. However, it is better to use VBScript as it is the default scripting language. 2. ASP or Active Server Page is a technology which enables you to create dynamic and interactive web pages. ASP Application development is of great demand on account of its easy interactivity. ASP pages have the extension ".asp". When a page with the extension .asp is requested by a browser the web server knows to interpret any ASP page contained within the web page before sending the HTML produced to the browser. Any web pages containing ASP cannot run by simply opening the page in a web browser. The page must be requested through a web server that supports ASP, and hence, ASP stands for Active Server Pages. 3. Active Server Pages or ASP and Hypertext-Pre-Processor are the two standards for web application development. ASP is created and widely distributed to large businesses and corporations. ASP applications are often used primarily on windows-based servers and not on UNIX. This is the reason why ASP is not used much for small and medium sized businesses. Instant ASP and Chili ASP are technologies that run ASP without Windows Operating System. In general, ASP applications are good for huge database projects that essentially offer high level of protection for privacy of databases. 4. ASP web hosting would refer to the services provided by the web hosting companies which offer support for ASP. If a user is browsing on a website which has been developed with the help of ASP, then the pages could be changed based on the user's actions. This type of code allows linking the pages of your website, in which the users can interact with the pages as they log in using their personal settings. They can also place orders interactively on your website. It also permits the users to access the data from a database, as well as interact with objects like Java components or ActiveX.

5. VBScript is the default scripting language which is used for writing ASP. Though VBScript is the most common language, a few other scripting languages like Java Script and Perl Script are also used. Any web page containing ASP Application Development cannot run by just viewing the web page in a particular browser. The web page must be requested and demanded through a server. ASP permits to modify a web page dynamically or insert any content in a web page. The major feature and advantage of using the Active Server Page is its low maintenance. An ASPdriven site is much simpler and less complicated than other sites. ASP codlings provide safety and security since the code cannot be observed from the browser.

7. Elements in Active Server Pages: 1. Array Functions:


Statemen t Array Purpose This function creates an instance of an array. The arguments to this function are the elements you want to see the array with. It is possible to have no arguments at all. aOption = Array("yes", "no", "unknown") Subroutine which clears all of the elements of the array. If the elements are numeric values, then they will all be set to zero. If the elements are strings then they will all be made empty. Erase(aYear) Selectively include or exclude elements from an array. The optional third argument is a boolean which indicates whether items are included. Filter(aArray, "remove", False) Build a string by joining all of the elements in the array. A "glue string" is inserted between each element. sCSV = Join(aArray, ",") Return the lower bound of an array meaning the smallest possible array index that may be used for the array. All arrays in ASP start with the index 0, so you shouldn't need to use this. nStart = LBound(aArray) Use this to re-dimension (or resize an array) after it has already been declared. If

Erase

Filter

Join

LBound

ReDim

the Preserve keyword is used, existing elements will not be destroyed in the process. ReDim Preserve aField(nCount + 10) Takes a string argument and creates an array by "splitting" the string into multiple elements. Strings are split based on a "delimitter" which is passed as the second argument. aName = Split("joe,bill,john", ",") Return the upper bound of the array meaning the last possible array index. This is often used to get the size of an array (which in turn can be used in For...Next loops to iterate over the elements) nLast = UBound(aArray)

Split

UBound

2. Variable and procedure Declarations:


Statement Purpose Const Used to declare a constant value (a value that will never change over the course of the program) Const PI = 3.1415926 Used to declare a variable in your program. Variables can be declared as "global" meaning available to the entire script or as local variables (inside a procedure) Dim I, J, K Used to declare a function in your script. A function is a procedure that should return a value but this is not enforced in Active Server Pages. Function YearsOld(dBirthDate) YearsOld = DateDiff("y", dBirthDate, Now()) End Function Used to declare a subroutine in your script. A subroutine cannot return a value to the caller. You don't have to declare a function or subroutine before calling it.

Dim

Function

Sub

Sub HelloWorld(sName) Response.Write "Hello " & sName End Sub

8. Operators in Active Server Pages: 1. Arithmetic operators:


Arithmetic operators are used to perform mathematical calculations. Operator + * / Function Addition Subtraction Multiplication Division Example aNumber = 2 + 2 aNumber = 4 - 2 aNumber = 10 * 10 a Number = 32 / 4 Result aNumber = 4 aNumber = 2 aNumber = 100 aNumber = 8

2. Comparison operators:
8

Comparison operators are used to compare two values and make a decision. Comparison operators return a true or false value. Operator = < > <> Function Equal to Less than Greater than Not equal to Example 9 = 10 aNumber = 5, aNumber < 10 aNumber = 5, aNumber > 10 5 <> 10 Result False True False True

3. Logical operators
Logical operators take the result produced by comparison operators and compares them to create new true or false values. For example, true AND false = false. Operator AND OR Not Function True if both are true, otherwise false Example 9 = 10 AND 10 = 10 Result False True False

True if at least one is true, otherwise false 9 = 10 OR 10 = 10 Reverses truth value 5=5

4. String operators

There is only one string operator and that is the concatenation operator "&". This operator is used to combine text strings.

Example: <% Dim stringOne = "This is " Dim stringTwo = "a text string"

Response.Write(stringOne & stringTwo & "<br />") Response.Write("ASP stands for " & "Active " & " Server " & " Pages ") %>

Output: This is a text string ASP stands for Active Server Pages

9. Event Driven Programming:

10

Event-driven programming allows developers to create code that will execute when a particular event occurs. For example, in the case of ASP, a particular segment of code can be executed when a page is either loaded or unloaded, or a control on a page is clicked. In contrast, ASP uses a linear code-processing model: each line of ASP code is mingled with static HTML and is processed in the order in which it appears in the ASP file. Event-driven programming makes ASP programming more closely parallel Windows programming. The advantages come from the fact that developers only need to write code to respond to events, and they can extend their knowledge of event-driven programming from the development of Windows desktop applications to Web applications. Another advantage of the event-driven programming model is that it allows for separation of the code that manipulates the data from the code that presents the data to the user. For example, ASP allows developers to use a mechanism called "code behind" to separate the logic of the Web application (typically written in VB.NET or C#) from the presentation (typically formatted by HTML). By separating the logic into a VB or C# (pronounced "C-sharp") code file (*.aspx.vb or *.aspx.cs) and a presentation code file (*.aspx), ASP allows multiple pages to use the same code, and makes maintenance easier because developers need not search through HTML statements in order to fix a programming logic problem. The steps are fairly straightforward:

An event happens The event is detected by the application The application responds to the event

The Windows OS will automatically detect when an event has occurred, like a mouse move, mouse click, form load, etc. If the OS doesn't find a VBA procedure relating to that event it will just go with its default behavior for that event. The programmer does not need to determine when a particular event happens as Windows does that for you. If you program a procedure to respond to that particular event, then it will override the default behavior for that event. Therefore, the programmer only needs to code those events where something other than the default behavior should occur. For example, the default behavior if a button is clicked is that the button gains focus. You only need to code any other tasks you wish to be performed when this event occurs.

11

Criticism and Best Practice: Event-driven programming is widely used in graphical user interfaces because it has been adopted by most commercial widget toolkits as the model for interaction. The design of those toolkits has been criticized for promoting an over-simplified model of event-action, leading programmers to create error prone, difficult to extend and excessively complex application code: Such an approach is fertile ground for bugs for at least three reasons:

1.
2.

It is not thread-safe. It can lead to writing code within the event handler for each possible value of

various values in the program, making the source code hard to understand.

3.
effects.

In places where the event code changes variables shared throughout the program,

it can require the programmer to write convoluted algorithms to avoid unwanted ripple

10. Query String in ASP:


The Query String collection property contains, and allows you to retrieve, the values of the variables in the query string which are the statements that follows a question mark. Many different processes can produce a query string such as an anchor tag, a form submission, or typing the string into the address box of the browser. The QueryString collection retrieves the values of the variables in the HTTP query string. The HTTP query string is specified by the values following the question mark (?). Several different processes can generate a query string. For example, the following anchor tag generates a variable named string with the value "this is a sample." <A HREF="example?string=this is a sample">string sample</A> Query strings are also generated by sending a form or by a user typing a query into the address box of the browser.

12

As a security precaution, always encode querystring input (or any request data) before using it. A general method of encoding data is to use Server.HTMLEncode. Another method is to write a short function that tests request data for invalid characters. More information can be found by reading chapter 12 of Writing Secure Code. Syntax:

Request.QueryString(variable)[(index)|.Count] Parameters:

variable Specifies the name of the variable in the HTTP query string to retrieve. index An optional parameter that enables you to retrieve one of multiple values forvariable. It can be any integer value in the range 1 to Request.QueryString(variable).Count.

You can use an iterator through a collection using a For Each item in ... Next loop. There is one mandatory argument. Variable The Variable specifies the name of the variable in the query string whose value is to be retrieved. There is one optional argument. Index The optional Index argument is used when the Variable argument has more than one value. It is an integer, ranging from 1 to Request.QueryString(Variable).Count, which is used to select values from the Variable. Count is the total number of multiple values.

13

Code: -----------------------File1.asp---------------------<HTML> <HEAD> </HEAD> <BODY> <A HREF="File2.asp?language=ASP&type=general">Query sample</A> </BODY> </HTML> -----------------------File2.asp---------------------<% For Each item In Request.QueryString Response.Write(item & " = " & Request.QueryString(item) & VbCrLf) Next %> Output: language = ASP type = general

11. ASP Objects:


Objects are a way of encapsulating multiple methods (they're like functions) and variables in one easy to manage Uber-Variable (an Object). Objects in ASP resemble other Object Oriented Programming languages. Objects were created to combat the increasing complexity of programming. The rationale for understanding and using Objects in your programming is to make programming easier and your code more human readable.

14

An object in ASP is created by passing a name string to theServer.CreateObject function(actually referred to as a method). The string to create a Message object is "CDO.Message". We will be creating a CDO.Message object in this example. Note: Because objects are special there is a special way that you create and destroy them using the Set keyword. These areas are marked in red in the example below. ASP Code:
<% Dim myObject Set myObject = Server.CreateObject("CDO.Message")

'You must Set your objects to "nothing" to free up the 'the computer memory that was allocated to it Set myObject = nothing %>

Objects are a collection of related things that are combined into this blob of programming goo that can be created and destroyed whenever we may need it. For example say that you wanted to make an object that allowed you to send an email... Well there are certain things all emails have: To, From, CC, Subject, etc. This list of variables that are common to every email would be quite tiresome to have to create for every email we sent. Wouldn't it be nice if we could create some sort of Uber-Variable (Object) that would group all these smaller variables into one thing?

15

12. Database Management through ASP:


ASP database is an online database management program that enables web-based editing of database tables in Microsoft Access and Microsoft SQL Server. ASPdatabase.net lets you view, edit, delete and create new records in a database table. Additionally, you can manage the tables themselves by creating new tables, dropping tables, adding columns to tables and deleting columns from tables. ASP database is ideal for web programmers who develop database driven websites and need to remotely access database files. Upload a Microsoft Access database file to your web server and use ASPdatabase.net to manage the database file with a web browser. ASPdatabase.net is also great for content managers to use as a data entry tool to databases on a remote website.

16

Das könnte Ihnen auch gefallen