0% found this document useful (0 votes)
33 views

web mca unit V

Uploaded by

Haa He
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

web mca unit V

Uploaded by

Haa He
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

ASP

Microsoft ASP(active server pages) is server side scripting environment developed


by Microsoft that can be used to create and run dynamic, interactive web server
applications.

Whenever your script runs on server side rather than the client side, web server does
all the work involved in generating the HTML pages then that can send to browser.

Using ASP, HTML pages are created dynamically according to client request. Asp
document contain the both HTML tags and server side scripting logic. Whenever
web server receives the http request for the asp document, a virtual output HTML
file is generated for the response by combining the HTML static information and the
HTML which is generated by the ASP.

The ASP files will have the extension called .ASP and asp file is a text file and it
contain the combination of the following

Text

Html tags

Script element (commands)

Process of servicing the ASP page (ASP architecture)

• The browser sends a request to the server for an active server page
• The web server receives the request and test the request is for an asp file
because the request file has extension called .asp
• The web server retrieves the proper asp file from the disk
• The web server sends the file to as special program called asp.dll (dynamic
link library)
• The generated html file is send to the browser

Client side scripting vs Server side scripting

Client side scripting

• Client side scripting is done usually using JavaScript or vbscript


• Client side scripting is often used for validation, interactivity and enhancing
the pages with active x controls and DHTML
• Validation is important for reducing the number of trips to the server and
reducing the servers work
• Client side scripts can access the browser and use features specific to the
browser
• There are some limitations with the client side scripting
o These are browser depended that means the scripting language must be
supported by the specific browser
o Client side script are viewable on the client i.e. protecting source code is
difficult

Server side scripting

• These scripts are reside on the server side that’s why programmers have
greater flexibility especially with the database access
• Scripts execute on the server usually generate dynamic response for the client
• The script queries database and dynamically generate HTML containing the
list and sends it to client
• Servers side scripts also have access to active x server components which
extend the scripting language functionality

Example program for ASP

<% @language =vbscript %>

<% option explicit %>


<html>

<head>

<title> first asp file</title>

</head>

<body>

<font color=”red” face=”arial”> first asp page</font>

<% =now() %>

</body>

</html>

Asp objects

Asp includes several built in objects. These objects enable user to extend
the power of scripts. The following are some of the asp object

Application object

It is used to store, retrieve the information that can be shared among the
users of an application. i.e the data which should be shared among users
should be stored in application object
An application on the Web may consist of several ASP files that work together to
perform some purpose. The Application object is used to tie these files together.

The Application object is used to store and access variables from any page, just like
the Session object. The difference is that ALL users share ONE Application object
(with Sessions there is ONE Session object for EACH user).

The Application object holds information that will be used by many pages in the
application (like database connection information). The information can be accessed
from any page. The information can also be changed in one place, and the changes
will automatically be reflected on all pages.
Request object

This object is used to store the information about the request send by the
browser. We can take that information from the request object to process..
Whenever submitting the form data that will be stored in request object.
The Request object is used to get information from a visitor .

Response object

This object is used to send the information back to browser. I.e. after
processing the request output can be send to response object from that
information can be transferred to browser.
The ASP Response object is used to send output to the user from the server.

Server object

This object allows user to use various utilities on the server for example
we can use the server object to control the length of the time that your
scripts run on the server machine
The Server object is used to access properties and methods on the server.

Session object

This object allows user to store and retrieve information about a particular
user session. The session object time property specify the time for the
session. The default value will be 20 minutes. The session also expires
when the browser is closed

Server side active x components


Server side script functionality is extended with the server side active X
components. These active X components do not have graphical user
interface and they reside on the web server. These components provide
powerful features to asp developers. Following are some of the server side
active X components are

Ad rotator

This component is used to display banners, advertisements on the web


page dynamically
You use the Ad Rotator component to alternately display a series of images, as well
as to provide a link from the displayed image to another URL. You keep a list of
advertisements in a text file; the Ad Rotator component displays them according to
the statements in your data file.

Browser capabilities

This component can be used to display different HTML content according


to the capabilities of different browsers
With the Browser Capabilities component, you can tailor the content you send to a
browser based on the browser's capabilities.

Content linking

Using this component we can create a link between the HTML pages so
that these can be navigated easily
The Content Linking component makes it easy for you to provide logical navigation
through the .asp files in an application. Rather than maintaining URL references in
a number of .asp files, you can specify the sequential organization of .asp files in a
single, easy-to-edit text file.

Page counter

This component use to count the number of visitors for the web page
The Page Counter component counts and displays the number of times a Web page
has been requested. At regular intervals it writes the number of hits to a text file so
that in the event of a server shutdown, the data is not lost.

Counter

This component use to count the number of visitors for the web site

Permission checker
The Permission Checker component tests the Web user’s access rights to a file or a
page. You can use the Permission Checker component to customize an ASP-based
page for different types of users. For example, if a Web page contained hyperlinks,
you could use the Permission Checker component to test the user's permissions for
the corresponding Web pages and omit or make inactive any links to pages for which
the user does not have access

Active x data object (ADO)


You use the Database Access component to provide access to a database from within
your Web application. You can then display the entire contents of a table, allow users
to construct queries, and perform other database operations from Web pages.
ADO
ADO stands for ActiveX Data Objects it is Microsoft Active-X component and it is
is automatically installed with Microsoft IIS. ADO is a programming interface to
access data in a database

Accessing a Database from an ASP Page


The common way to access a database from inside an ASP page is to:

1. Create an ADO connection to a database


2. Open the database connection
3. Create an ADO recordset
4. Open the recordset
5. Extract the data you need from the recordset
6. Close the recordset
7. Close the connection
The FileSystemObject Object
The FileSystemObject object is used to access the file system on a server.

This object can manipulate files, folders, and directory paths. It is also possible to
retrieve file system information with this object.

The following code creates a text file (c:\test.txt) and then writes some text to the
file:
<%
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("c:\test.txt",true)
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
%>

The FileSystemObject object's properties and methods are described below:

Property Description

Drives Returns a collection of all Drive objects on the computer

Methods

Method Description

Build path Appends a name to an existing path

CopyFile Copies one or more files from one location to another

CopyFolder Copies one or more folders from one location to another

CreateFolder Creates a new folder

CreateTextFile Creates a text file and returns a TextStream object that can

be used to read from, or write to the file


DeleteFile Deletes one or more specified files

DeleteFolder Deletes one or more specified folders

DriveExists Checks if a specified drive exists

FileExists Checks if a specified file exists

FolderExists Checks if a specified folder exists

MoveFile Moves one or more files from one location to another

MoveFolder Moves one or more folders from one location to another

Session tracking

Session Tracking tracks a user's requests and maintains their state. It is a mechanism
used to store information on specific users and in order to recognize these user's
requests when they connect to the web server. HTTP is a stateless protocol where
each request to the server is treated like a new request.

The Session object

When you are working with an application on your computer, you open it, do some
changes and then you close it. This is much like a Session. The computer knows who
you are. It knows when you open the application and when you close it. However,
on the internet there is one problem: the web server does not know who you are and
what you do, because the HTTP address doesn't maintain state.

ASP solves this problem by creating a unique cookie for each user. The cookie is
sent to the user's computer and it contains information that identifies the user. This
interface is called the Session object.

The Session object stores information about, or change settings for a user session.

Variables stored in Session object hold information about one single user, and are
available to all pages in one application. Common information stored in session
variables is name, id, and preferences. The server creates a new Session object for
each new user, and destroys the Session object when the session expires.
Cookies

Cookies are small pieces of data created by a website and stored on a user's device
via the web browser . These text files contain information such as user preferences,
login details, and browsing history, helping websites remember users, tailor content,
and enhance browsing experiences . Cookies are categorized into various types,
including session cookies (which expire when the browser is closed) and persistent
cookies (which remain on the device until deleted or expired) . They are commonly
used for functionalities like remembering login sessions, analyzing site usage, and
delivering personalized content.

A cookie is often used to identify a user. A cookie is a small file that the server
embeds on the user's computer. Each time the same computer requests a page with
a browser, it will send the cookie too. With ASP, you can both create and retrieve
cookie values.

The "Response.Cookies" command is used to create cookies.

Note: The Response.Cookies command must appear BEFORE the <html> tag.

Ex:

<%
Response.Cookies("firstname")="Alex"
%>

The "Request.Cookies" command is used to retrieve a cookie value.

In the example below, we retrieve the value of the cookie named "firstname" and
display it on a page:

<%
fname=Request.Cookies("firstname")
response.write("Firstname="&fname)
%>
XML
XML stands for extensible Markup Language.

XML was designed to store and transport data.

XML was designed to be both human- and machine-readable.

XML is a software- and hardware-independent tool for storing and transporting data.

XML was designed to be self-descriptive

XML is a W3C Recommendation

XML Example 1

<?xml version="1.0" encoding="UTF-8"?>


<note>
<to>raju</to>
<from>srinu</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The XML above is quite self-descriptive:

• It has sender information.


• It has receiver information
• It has a heading
• It has a message body.

The Difference Between XML and HTML

XML and HTML were designed with different goals:

• XML was designed to carry data - with focus on what data is


• HTML was designed to display data - with focus on how data looks
• XML tags are not predefined like HTML tags.

XML Simplifies Things

• It simplifies data sharing


• It simplifies data transport
• It simplifies platform changes
• It simplifies data availability

Many computer systems contain data in incompatible formats. Exchanging data


between incompatible systems (or upgraded systems) is a time-consuming task for
web developers. Large amounts of data must be converted, and incompatible data is
often lost.

XML stores data in plain text format. This provides a software- and hardware-
independent way of storing, transporting, and sharing data.

XML also makes it easier to expand or upgrade to new operating systems, new
applications, or new browsers, without losing data.

With XML, data can be available to all kinds of "reading machines" like people,
computers, voice machines, news feeds, etc.

XML Tree

XML documents form a tree structure that starts at "the root" and branches to "the
leaves".
An Example XML Document

The image above represents books in this XML:

<?xml version="1.0" encoding="UTF-8"?>


<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>abc</author>
<year>2018</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

XML Syntax Rules


The syntax rules of XML are very simple and logical. The rules are easy to learn,
and easy to use.

This line is called the XML prolog:

<?xml version="1.0" encoding="UTF-8"?>

The XML prolog is optional. If it exists, it must come first in the document.

To avoid errors, you should specify the encoding used, or save your XML files as
UTF-8.

UTF-8 is the default character encoding for XML documents.

In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

XML tags are case sensitive. The tag <Letter> is different from the tag <letter>.

Opening and closing tags must be written with the same case:

In XML, all elements must be properly nested within each other:

XML elements can have attributes in name/value pairs just like in HTML.

In XML, the attribute values must always be quoted:

Entity References

Some characters have a special meaning in XML.

If you place a character like "<" inside an XML element, it will generate an error
because the parser interprets it as the start of a new element.

This will generate an XML error

<message>salary < 1000</message>

To avoid this error, replace the "<" character with an entity reference:

<message>salary &lt; 1000</message>

There are 5 pre-defined entity references in XML:


&lt; < less than

&gt; > greater than

&amp; & ampersand

&apos; ' apostrophe

&quot; " quotation mark

Well Formed XML

XML documents that conform to the syntax rules above are said to be "Well
Formed" XML documents.

XML Elements

An XML document contains XML Elements.

What is an XML Element?

An XML element is everything from (including) the element's start tag to (including)
the element's end tag.

<price>29.99</price>

An element can contain:

text

attributes

other elements

• or a mix of the above

<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

In the example above:

<title>, <author>, <year>, and <price> have text content because they contain text
(like 29.99).

<bookstore> and <book> have element contents, because they contain elements.

<book> has an attribute (category="children").

XML Naming Rules

XML elements must follow these naming rules:

• Element names are case-sensitive


• Element names must start with a letter or underscore
• Element names cannot start with the letters xml (or XML, or Xml, etc)
• Element names can contain letters, digits, hyphens, underscores, and periods
• Element names cannot contain spaces

Any name can be used; no words are reserved (except xml).

XML Attributes

XML elements can have attributes, just like HTML.

Attributes are designed to contain data related to a specific element.

XML Attributes Must be Quoted

Attribute values must always be quoted. Either single or double quotes can be used.
For a person's gender, the <person> element can be written like this:

<person gender="female">

or like this:

<person gender='female'>

If the attribute value itself contains double quotes you can use single quotes, like in
this example:

XML Namespaces

XML Namespaces provide a method to avoid element name conflicts.

Name Conflicts

In XML, element names are defined by the developer. This often results in a conflict
when trying to mix XML documents from different XML applications.

This XML carries HTML table information:

<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>

This XML carries information about a table (a piece of furniture):

<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>

If these XML fragments were added together, there would be a name conflict. Both
contain a <table> element, but the elements have different content and meaning.

A user or an XML application will not know how to handle these differences.
Solving the Name Conflict Using a Prefix

Name conflicts in XML can easily be avoided using a name prefix.

This XML carries information about an HTML table, and a piece of furniture:

<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>

<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>

In the example above, there will be no conflict because the two <table> elements
have different names.

XML Namespaces - The xmlns Attribute

When using prefixes in XML, a namespace for the prefix must be defined.

The namespace can be defined by an xmlns attribute in the start tag of an element.

The namespace declaration has the following syntax. xmlns:prefix="URI".

<root>

<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="https://www.w3.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>

</root>

In the example above:

The xmlns attribute in the first <table> element gives the h: prefix a qualified
namespace.

The xmlns attribute in the second <table> element gives the f: prefix a qualified
namespace.

When a namespace is defined for an element, all child elements with the same prefix
are associated with the same namespace.

XML Parser

All major browsers have a built-in XML parser to access and manipulate XML.

XML Parser

The XML DOM (Document Object Model) defines the properties and methods for
accessing and editing XML.

However, before an XML document can be accessed, it must be loaded into an XML
DOM object.

All modern browsers have a built-in XML parser that can convert text into an XML
DOM object.

Parsing a Text String

This example parses a text string into an XML DOM object, and extracts the info
from it with JavaScript:

Example
<html>
<body>

<p id="demo"></p>

<script>
var text, parser, xmlDoc;

text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";

parser = new DOMParser();


xmlDoc = parser.parseFromString(text,"text/xml");

document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>

</body>
</html>

What is the DOM?

The DOM defines a standard for accessing and manipulating documents:

"The W3C Document Object Model (DOM) is a platform and language-neutral


interface that allows programs and scripts to dynamically access and update the
content, structure, and style of a document."

The HTML DOM defines a standard way for accessing and manipulating HTML
documents. It presents an HTML document as a tree-structure.

Understanding the DOM is a must for anyone working with HTML or XML.

XML DTD

An XML document with correct syntax is called "Well Formed".

An XML document validated against a DTD is both "Well Formed" and "Valid".
Valid XML Documents

A "Valid" XML document is a "Well Formed" XML document, which also conforms
to the rules of a DTD:

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>raju</to>
<from>srinu</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The DOCTYPE declaration, in the example above, is a reference to an external DTD


file. The content of the file is shown in the paragraph below.

XML DTD

The purpose of a DTD is to define the structure of an XML document. It defines the
structure with a list of legal elements:

<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

The DTD above is interpreted like this:

• !DOCTYPE note defines that the root element of the document is note
• !ELEMENT note defines that the note element must contain the elements: "to, from,
heading, body"
• !ELEMENT to defines the to element to be of type "#PCDATA"
• !ELEMENT from defines the from element to be of type "#PCDATA"
• !ELEMENT heading defines the heading element to be of type "#PCDATA"
• !ELEMENT body defines the body element to be of type "#PCDATA"
#PCDATA means parse-able text data.

XML Schema

An XML Schema describes the structure of an XML document, just like a DTD.

An XML document with correct syntax is called "Well Formed".

An XML document validated against an XML Schema is both "Well Formed" and
"Valid".

XML Schema

XML Schema is an XML-based alternative to DTD:

<xs:element name="note">

<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>

</xs:element>

The Schema above is interpreted like this:

• <xs:element name="note"> defines the element called "note"


• <xs:complexType> the "note" element is a complex type
• <xs:sequence> the complex type is a sequence of elements
• <xs:element name="to" type="xs:string"> the element "to" is of type string (text)
• <xs:element name="from" type="xs:string"> the element "from" is of type string
• <xs:element name="heading" type="xs:string"> the element "heading" is of type string
• <xs:element name="body" type="xs:string"> the element "body" is of type string

XML Schemas are More Powerful than DTD

• XML Schemas are written in XML


• XML Schemas are extensible to additions
• XML Schemas support data types
• XML Schemas support namespaces

XML Schemas Support Data Types

One of the greatest strengths of XML Schemas is the support for data types:

• It is easier to describe document content


• It is easier to define restrictions on data
• It is easier to validate the correctness of data
• It is easier to convert data between different data types

PERL AND CGI

Practical Extraction and Report Language (Perl) is one of the most widely used
languages for Web programming today. Larry Wall began developing this high-level
programming language in 1987 while working at Unisys. His initial intent was to
create a programming language to monitor large software projects and generate
reports. Wall wanted to create a language that would be more powerful than shell
scripting and more flexible than C, a language with rich text-processing capabilities
and, most of all, and a language that would make common programming tasks
straightforward and easy.

The Common Gateway Interface (CGI) is a standard interface through which users
interact with applications on Web servers. Thus, CGI provides a way for clients (e.g.,
Web browsers) to interface indirectly with applications on the Web server. Because
CGI is an interface, it cannot be programmed directly; a script or executable program
(commonly called a CGI script) must be executed to interact with it. While CGI
scripts can be written in many different programming languages, Perl is commonly
used because of its power, its flexibility and the availability of preexisting scripts.
String Processing and Regular Expressions

One of Perl’s most powerful capabilities is the processing of textual data easily and
efficiently, which allows for straightforward searching, substitution, extraction and
concatenation of strings. Text manipulation in Perl is usually done with a regular
expression—a series of characters that serves as a pattern-matching template (or
search criterion) in strings, text files and databases. This feature allows complicated
searching and string processing to be performed using relatively simple expressions.

Qualifier matches

{n} Exactly n times

{m,n} Between m and n times inclusive

{n,} n or more times

+ One or more times (same as {1,})

* Zero or more times (same as {0,})

? One or zero times (same as {0,1})


Symbol matches Sumbol matches

^ Beginning of line \d Digit (i.e., 0 to 9)

$ End of line \D Nondigit

\b Word boundary \s Whitespace

\B Nonword boundary \S Nonwhitespace

\w Word (alphanumeric) \n Newline


character

\W Nonword character \t Tab

Ex:

# a three digits, each followed by a whitespace


# character (eg "3 4 5 ")
/(\d\s) {3}/

# string starts with one or more digits


/^\d+/

# string that ends with one or more digits


/\d+$/

Server-Side Includes

Dynamic content greatly improves the look-and-feel of a Web page. Pages that
include the current date or time, rotating banners or advertisements, a daily message,
special offers or company news are attractive because they are current. Clients see
new information on every visit and thus will likely revisit the site in the future.
Server-Side Includes (SSIs) is commands embedded in XHTML documents to create
simple dynamic content. SSI commands like ECHO and INCLUDE enable the
inclusion on Web pages of content that is constantly changing (i.e., the current time)
or information that is stored in a database. The command EXEC can be used to run
CGI scripts and embed their output directly into a Web page.

Not all Web servers support the available SSI commands. Therefore, SSI commands
are written as XHTML comments (e.g., <!--#ECHO VAR="DOCUMENT_NAME"
-->). Servers that do not recognize these commands treat them as comments. Some
servers do support SSI commands, but only if they are configured to do so

XHTML (Extensible HyperText Markup Language) is a markup language that


combines the features of HTML and XML. It follows stricter syntax rules similar to
XML while maintaining compatibility with HTML. XHTML is designed to be well-
formed and compatible with XML parsers, enabling easier integration with other
XML-based technologies. It extends HTML by adding stricter rules for syntax and
structure, promoting cleaner code and improved cross-browser compatibility.
XHTML documents must adhere to XML standards, making them more precise and
allowing for better error detection.

Cookies and Perl

Cookies maintain state information for each client who uses a Web browser.
Preserving this information allows data and settings to be retained even after the
execution of a CGI script has ended. Cookies are used to record preferences (or other
information) for the next time the client visits a Web site. For example, many Web
sites use cookies to store each client’s postal zip code. The zip code is used when
the client asks a Web page to send, for instance, current weather information or news
updates for the client’s region. On the server side, cookies may be used to track
information about client activity in order to determine which sites are visited most
frequently or how effective certain advertisements and products are.
Microsoft Internet Explorer stores cookies as small text files saved on the client’s
hard drive. The data stored in the cookies is sent back to the server whenever the
user requests a Web page from that server. The server can then serve XHTML
content to the client that is specific to the information stored in the cookie.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy