web mca unit V
web mca unit V
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
• 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
•
• 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
<head>
</head>
<body>
</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
Ad rotator
Browser 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
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
%>
Property Description
Methods
Method Description
CreateTextFile Creates a text file and returns a TextStream object that can
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.
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.
Note: The Response.Cookies command must appear BEFORE the <html> tag.
Ex:
<%
Response.Cookies("firstname")="Alex"
%>
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 is a software- and hardware-independent tool for storing and transporting data.
XML Example 1
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 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.
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:
XML elements can have attributes in name/value pairs just like in HTML.
Entity References
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.
To avoid this error, replace the "<" character with an entity reference:
XML documents that conform to the syntax rules above are said to be "Well
Formed" XML documents.
XML Elements
An XML element is everything from (including) the element's start tag to (including)
the element's end tag.
<price>29.99</price>
text
attributes
other elements
<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>
<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.
XML Attributes
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
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.
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
<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
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.
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.
<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>
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.
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>";
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>
</body>
</html>
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 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 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)>
]>
• !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 validated against an XML Schema is both "Well Formed" and
"Valid".
XML Schema
<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>
One of the greatest strengths of XML Schemas is the support for data types:
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
Ex:
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
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.