Web Development Internet Protocols
Web Development Internet Protocols
There are three basic features that make HTTP a simple but powerful protocol:
HTTP is connectionless: The HTTP client, i.e., a browser initiates an HTTP request
and after a request is made, the client waits for the response. The server processes
the request and sends a response back after which client disconnect the connection.
So client and server knows about each other during current request and response
only. Further requests are made on new connection like client and server are new to
each other.
HTTP is media independent: It means, any type of data can be sent by HTTP as
long as both the client and the server know how to handle the data content. It is
required for the client as well as the server to specify the content type using
appropriate MIME-type.
HTTP is stateless: As mentioned above, HTTP is connectionless and it is a direct
result of HTTP being a stateless protocol. The server and client are aware of each
other only during a current request. Afterwards, both of them forget about each
other. Due to this nature of the protocol, neither the client nor the browser can retain
information between different requests across the web pages.
Basic Architecture of HTTP
The following diagram shows a very basic architecture of a web application and
depicts where HTTP sits:
Fig. 1. Architecture of HTTP
URL
Every document on the Web has a unique address. This address is known as Uniform
Resource Locator (URL).
Several HTML/XHTML tags include a URL attribute value, including hyperlinks,
inline images, and forms. All of them use the same syntax to specify the location of a web
resource, regardless of the type or content of that resource. That's why it is known a
Uniform Resource Locator.
URL Elements
A URL is made of up several parts, each of which offers information to the web
browser to help find the page. It is easier to learn the parts of a URL, if you look at the
example URL given below, there are three key parts: the scheme, the host address, and
the file path. The following section will discuss each of them:
http://www.tutorialspoint.com/index.htm
The Scheme
The scheme identifies the type of protocol and URL you are linking to and therefore,
how the resource should be retrieved. For example, most web browsers use Hypertext
Transfer Protocol (HTTP) to pass information to communicate with the web servers and
this is the reason a URL starts with http://.
There are other schemes available and you can use either of them based on your
requirement:
S. Scheme & Description
No.
1 http://
Hypertext Transfer Protocol (HTTP) is used to request pages from Web servers
and send them back from Web servers to browsers.
2 https://
Secure Hypertext Transfer Protocol (HTTPS) encrypts the data sent between the
browser and the Web server using a digital certificate.
3 ftp://
File Transfer Protocol is another method for transferring files on the Web. While
HTTP is a lot more popular for viewing Web sites because of its integration with
browsers, FTP is still commonly used protocol to transfer large files across the
Web and to upload source files to your Web server.
4 file://
Used to indicate that a file is on the local hard disk or a shared directory on a
LAN.
WEB BROWSERS
Web Browser is an application software that allows us to view and explore information on
the web. User can request for any web page by just entering a URL into address bar.
Web browser can show text, audio, video, animation and more. It is the responsibility of a
web browser to interpret text and commands contained in the web page.
Earlier the web browsers were text-based while now a days graphical-based or voice-
based web browsers are also available. Following are the most common web browser
available today:
Browser Vendor
Internet Explorer Microsoft
Google Chrome Google
Mozilla Firefox Mozilla
Netscape Navigator Netscape Communications Corp.
Opera Opera Software
Safari Apple
Sea Monkey Mozilla Foundation
K-meleon K-meleon
Architecture
There are a lot of web browser available in the market. All of them interpret and
display information on the screen however their capabilities and structure varies
Depending upon implementation. But the most basic component that all web
browser must exhibit are listed below:
Controller/Dispatcher
Interpreter
Client Programs
Controller works as a control unit in CPU. It takes input from the keyboard or
mouse, interpret it and make other services to work on the basis of input it receives.
Interpreter receives the information from the controller and execute the instruction
line by line. Some interpreter are mandatory while some are optional For example,
HTML interpreter program is mandatory and java interpreter is optional.
Client Program describes the specific protocol that will be used to access a
particular service. Linking of Different Protocols are mentioned in the figure 1.11.
Following are the client programs that are commonly used:
HTTP
SMTP
FTP
NNTP
POP
Figure 1.11 Different Client Protocols
1. The Web browser should be able to look at the Web pages throughout Internet
or to connect to various sites to access information, explore resources and have fun.
2. The Web browser must enable you to follow the hyperlinks on a Web and
type in a URL for it to follow.
4. Your browser ought to include an easy way to get on-line help as well as built
in links to other resources on the Web that can give you helps or answer your
questions.
5. You will definitely want a way to save links to the sites you have visited on
the WWW so that you can get back to them during other sessions. Web browsers
take care of those in two ways, through a come across in the current in the session,
and a bookmark list, which you use to keep a list of WWW pages you want to
access any time you use your browser. The name of the site and its URL are kept
in these lists. The bookmark list is particularly important and the browser contain
tools to manage and arrange it.
7. Browser give you the facility to save a Web page in a file on your com pull
print a Web page on your computer, and send the contents of a Web page e-Mail
to others on the Internet.
8. Few Web browser are complete Internet package, means they come with
components like e-Mail client, newsgroup client an HTML composer, telnet
client, ftp client, etc.
9. Web browser should be able to handle text, images of the World Wide Web,
as well as the hyperlinks to digital video, or other types of information.
10. To take advantage of some of the most exciting things on the World Wide
Web, your browser needs to properly display and handle Web pages that contain
animated or interactive items. Netscape Navigator can incorporate these features
through its ability to interpret programs written in Java and Java Script.
11. Web browsers interact not just with the Web, but also with your computer’s
operating system and with other programs, called plug-ins, that gives the
browser enhanced features.
12. Another important feature to insist on in your browser is caching. A browser that
caches keeps of the pages you visit so that it does not have to download them
again if you want to return to them. Reloading a page from the cache is much quicker
that downloading it again from the original source.
13. The most important feature of any browser is ease of use. While all Web browser
are fundamentally simple to use, the one you settle on should be very easy to work
with; it should function as a transparent windom onto the Web.
14. If you will be browser the Web from within a secured network, you may have to
configure your browser to work through a special computer on your network
called a proxy server.
WEB SERVERS
A web server is server software, or hardware dedicated to running this software, that can
satisfy client requests on the World Wide Web. A web server can, in general, contain one
or more websites. A web server processes incoming network requests over HTTP and
several other related protocols.
The primary function of a web server is to store, process and deliver web pages to
clients.[1] The communication between client and server takes place using the Hypertext
Transfer Protocol (HTTP). Pages delivered are most frequently HTML documents, which
may include images, style sheets and scripts in addition to the text content.
Web Server working is mentioned in the figure 1.12. Web server respond to the client request in
either of the following two ways:
• Sending the file to the client associated with the requested URL.
Note:
• When client sends request for a web page, the web server search for the
requested page if requested page is found then it will send it to client with
an HTTP response.
• If the requested web page is not found, web server will the send an HTTP
response: Error 404 Not found.
• If client has requested for some other resources then the web server will
contact to the application server and data store to construct the HTTP
response.
Some Examples
Following table describes the most leading web servers available today:
S. No. Scheme & Description
This is the most popular web server in the world developed by the Apache
Software Foundation. Apache web server is an open source software and can be
installed on almost all operating systems including Linux, UNIX, Windows,
FreeBSD, Mac OS X and more. About 60% of the web server machines run the
Apache Web Server.
2 Internet Information Services (IIS)
The Internet Information Server (IIS) is a high performance Web Server from
Microsoft. This web server runs on Windows NT/2000 and 2003 platforms (and
may be on upcoming new Windows version also). IIS comes bundled with
Windows NT/2000 and 2003; Because IIS is tightly integrated with the operating
system so it is relatively easy to administer it.
3 Lighttpd
The lighttpd, pronounced lighty is also a free web server that is distributed with
the FreeBSD operating system. This open source web server is fast, secure and
consumes much less CPU power. Lighttpd can also run on Windows, Mac OS X,
Linux and Solaris operating systems.
4 Sun Java System Web Server
This web server from Sun Microsystems is suited for medium and large web sites.
Though the server is free it is not open source. It however, runs on Windows,
Linux and UNIX platforms. The Sun Java System web server supports various
languages, scripts and technologies required for Web 2.0 such as JSP,
Java Servlets, PHP, Perl, Python, and Ruby on Rails, ASP and Coldfusion etc.
5 Jigsaw Server
Jigsaw (W3C's Server) comes from the World Wide Web Consortium. It is
open source and free and can run on various platforms like Linux, UNIX,
Windows, and Mac OS X Free BSD etc. Jigsaw has been written in Java and can
run CGI scripts and PHP programs.
It is usually used to provide interactive web sites that interface to databases or other data
stores. This is different from client-side scripting where scripts are run by the viewing
web browser, usually in JavaScript. The primary advantage to server-side scripting is the
ability to highly customize the response based on the user's requirements, access rights,
or queries into data stores.
When the server serves data in a commonly used manner, for example according to the
HTTP or FTP protocols, users may have their choice of a number of client programs. In
the case of more specialized applications, programmers may write their own server, client,
and communications protocol, that can only be used with one another.
Programs that run on a user's local computer without ever sending or receiving data over
a network are not considered clients, and so the operations of such programs would not
be considered client-side operations.
Some of the technologies designed mainly or exclusively for server-side scripting, typically
by embedding instructions directly in template web pages are as follows:
The Common Gateway Interface (CGI) is a set of rules that specifies how parameters are
passed from programs to Web servers. When a user submits a form, a program may be
executed by the Web server, and the results are returned to the browser. The particular
program that is to be executed is specified in the ACTION attribute of the form tag. In
general, any program run by a Web server in response to a user’s request is called a script
or CGI script.
A plain HTML document is static i.e. constant whereas a CGI program is dynamic i.e.
executed on real time.
A CGI program is executed by the web daemon to transmit the information to the
database engine and return the result to the client. Thus it is called as a gateway.
It can be written in any language like C/C++, FORTRAN, Visual Basic, etc.
So that the browser knows what kind of document it is and therefore how to display it.
To send plain ASCII documents one can use text/plain. For multimedia documents like
sound and images the content should be specified appropriately.
The second line (important) must be blank (a line feed), reserved for future development.
Forms
Usually the information supplied by the QUERY_STRING variable should come from the
user pressing buttons and entering text in HTML document. This information to be
packaged and sent to the CGI script. Each group of buttons and text boxes is called a
form. The user also has to tell it the URL to send the information to, and how the
information is sent. The result is something like this:
The action attribute of the tag gives the URL of the CGI script.
2. After the user fills out the form and clicks the "submit" button, the Web server directs the data to a
CGI program. The program may examine the data to make sure the user provided all the
information necessary to process the order.
4. After the database receives the information, it creates an Order Number for the user, and sends it
back to the CGI program.
5. The CGI program then creates a web page containing the user's Order Number and thanking him
for the order.
6. The CGI program hands the web page off to the Web server, which then sends it to the user.
CGI programs are the most common way for Web servers to interact dynamically with users. Many
HTML pages that contain forms, for example, use a CGI program to process the form's data once
it's submitted. Web servers often have a cgi-bin directory at the base of the directory tree to hold
executable files called with CGI.
Another increasingly common way to provide dynamic feedback for Web users is to include scripts
or programs that run on the user's machine rather than the Web server. These programs can be Java
applets, Java scripts, or ActiveX controls. These technologies are known collectively as client-side
solutions, while the use of CGI is a server-side solution because the processing occurs on the Web
server.
For example, suppose we wanted to "hook up" our Unix database to the World Wide Web, to
allow people from all over the world to query it. Basically, we need to create a CGI program that
the Web server will execute to transmit information to the database engine, and receive the results
back again and display them to the client. This is an example of a gateway, and this is where CGI,
currently version 1.1, got its origins.
Each time a request is received; the server analyzes what the request asks for, and returns the
appropriate output. The two basic methods for the server to do this are the following:
If the request identifies a file stored on disk, then return the contents of that file.
If the request identifies an executable command and possibly arguments, then run the command
and return its output.
One problem with CGI is that each time a CGI script is executed, a new process is started. For
busy Web sites, this can slow down the server noticeably.
Drawbacks
In the case that a CGI call involves use of a scripting language such as perl, coding errors are
highly likely to result in code injection vulnerability.
Calling a command generally means the invocation of a newly created process. Starting up the
process can take up much more time and memory than the actual work of generating the output,
especially when the program still needs to be interpreted or compiled. If the program is called
often, the workload can quickly overwhelm web servers. However, this overload may be reduced
by using compiled CGI programs, such as those in C/C++, rather than using Perl or other scripting
languages with CGI. Such performance issues are usually only a concern on machines that
experience a high load.
3. The CGI Software then performs whatever 8. The CGI Software takes the information
validation of this information that is required. For from the database, and manipulates it into
instance, it checks to see if an email address is the format that is desired.
valid. If this is a database program, the CGI
Software prepares a database statement, to either 9. If any static html pages need to be created
add, edit or delete information from the database. (or similar task needs to be performed), the
CGI program accesses the web server
4. The CGI Software then executes the prepared computer's file system, and reads, writes,
database statement, which is passed to the database and/or edits files.
driver.
10. The CGI Software then sends the result
5. The database driver acts as a middleman, and it wants the web surfer's browser to see
performs the requested action on the database back to the web server.
itself.
11. The web server sends the result it got
from the CGI Software back to the web
surfer's browser.
VBScript
“VBSCRIPT (SHORT FOR VISUAL BASIC SCRIPTING EDITION) IS AN ACTIVE
SCRIPTING LANGUAGE DEVELOPED BY MICROSOFT.”
Besides client-side web development, VBScript is used for server-side processing of web pages,
most notably with Microsoft Active Server Pages (ASP).
VBScript can also be used to create applications that run directly on a person's computer
running Microsoft Windows.
Binary file and memory I/O is provided by the "ADODB.Stream" class, which can also be
used as a string builder (since a high amount of VBScript string concatenation is costly
due to constant memory re-allocation), and can be used to convert an array of bytes to a
string and vice versa.
Database access is made possible through ActiveX Data Objects (ADO), and the
IIS Metabase can be manipulated using the GetObject() function with sufficient
permissions.
Scripting languages like VBScript and JavaScript, are designed as an extension to HTML.
The Web browser receives scripts along with the rest of the web document. It is the
browser’s responsibility to parse and process the scripts. HTML was extended to include
a tag that is used to incorporate scripts into HTML – the <SCRIPT> tag.
For example,
<HTML>
<HEAD>
<TITLE>Working with VBScript</TITLE>
<SCRIPT LANGUAGE=”VBScript”>
<!--
MsgBox “Welcome to my Web page !”
//->
</SCRIPT>
</HEAD>
</HTML>
The Process of validating forms involves checking the form to see if:
Checking the Form input may involve determining whether the input given by the client
is correct or not. For example, if a web page is about to ask for a password from the user,
then if the user enter the correct password, the web page may continue its process.
Otherwise, if the user enters a wrong password, the web page may display a message to
the user like “The password is Incorrect!!”.
Submitting the form after validation involves the use a button that is tied to an event
procedure that both validates and at the same time submits the form.
Lifetime of Variables
A variable declared outside a procedure can be accessed and changed by any script in
the ASP file. A variable declared inside a procedure is created and destroyed every time
the procedure is executed.
To declare variables accessible to more than one ASP file, declare them as session
variables or application variables.
Session Variables
Session variables are used to store information about ONE single user, and are
available to all pages in one application. Typically information stored in session
variables are name, id, and preferences.
Application Variables
Application variables are also available to all pages in one application. Application
variables are used to store information about ALL users in a specific application.
Procedures
The ASP source code can contain procedures and functions:
<html>
<head>
<% sub vbproc(num1,num2)
Response.write(num1*num2)
end sub
%>
</head>
<body>
<p> Result: <% call vbproc(3,4) %></p>
</body>
</html>
Insert the <%@language=”language”%> line above the <html> tag to write
procedures or functions in another scripting language than default:
<%@ language=”javascript” %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.write(num1*num2)
}
%>
</head>
<body>
<p> Result: <% jsproc(3,4) %></p>
</body>
</html>
User Input
The request object may be used to retrieve user information from forms.
For example:
<form method=”get” action=”simpleform.asp”>
First Name: <input type=”text” name=”fname” /> <br />
Last Name: <input type=”text” name=”lname” /><br /><br />
<input type=”submit” value=”Submit” />
</form>
User input can be retrieved in two ways: With Request.QueryString or Request.form
Request.QueryString
This command is used to collect values in a form with method= “get”. Information sent
from a form with the GET method is visible to everyone (will be displayed in the browser’s
address bar) and has limits on the amount of information to send.
If a user typed “pankaj” and “sharma” in the form example above, the URL sent to the
server would look like this:
http://www.abes.ac.in/simpleform.asp?fname=pankaj&lname=sharma
Assume that the ASP file “simpleform.asp” contains the following script:
<body>
Welcome
<% response.write(request.querystring(“fname”))
Response.write(“ ” & request.querystring(“lname”))
%>
</body>
The browser will display the following in the body of the document:
Welcome pankaj Sharma
Request.Form
This command is used to collect values in a form with method= “post”. Information sent
from a form with the POST method is invisible to others and has no limits on the amount
of information to send.
If a user typed “Bill” and “Gates” in the form example above, the URL sent to the server
would look like this:
Http://www.abes.ac.in/simpleform.asp
Assume that the ASP file “simpleform.asp” contains the following script:
<body>
Welcome
<%
Response.write(request.form(“fname”))
Response.write(“ ” & request.form(“lname”))
%>
</body>
The browser will display the following in the body of the document:
Welcome Bill Gates
Form Validation
User input should be validated on the browser whenever possible (by client scripts).
Browser validation is faster and reduces the server load.
Using server validation should be considered if the user input will be inserted into a
database. A good way to validate a form on the server is to post the form to itself, instead
of jumping to a different page. The user will then get the error messages on the same
page as the form. This makes it easier to discover the error.
Advantages of ASP
• It gives dynamism to the pages created.
• Interactive pages reflecting the preferences of the user can be developed.
• ASP is a very good innovation to dynamic web programming.
• Data obtaining and displaying became more easy and efficient.
Disadvantages of ASP
• It is slower than most of similar technologies.
• Not very much portable.
Java Server Pages (JSP)
“JAVASERVER PAGES (JSP) IS A JAVA TECHNOLOGY THAT ALLOWS SOFTWARE
DEVELOPERS TO DYNAMICALLY GENERATE HTML, XML OR OTHER TYPES OF
DOCUMENTS IN RESPONSE TO A WEB CLIENT REQUEST.”
The technology allows java code and certain pre-defined actions to be embedded into
static content..”
Features of JSP
JSP gives an ideal platform for creating web applications easily and quickly. The various
features supported by JSP are:
1. Platform and Server Independence. The JSP technology follows the ‘write
once’ run anywhere, rule which is the basis of the java language. JSP technology
can run on various web server including Apache, Netscape and IIS and is
supported by a large variety of tools from different vendors.
2. Environment. JSP uses pure java and takes full advantage of its object-
oriented nature. This technology lets the designer separate content generation
from layout by accessing component from the page.
3. Extensible JSP Tags. JSP uses a combination of tags and scripting to create
dynamic web pages. It allows the designer to extend the JSP tags available. JSP
developers can create custom tag libraries, so that more functionality can be
extracted using XML-like tags and this leads to less use of scripting in JSP pages.
4. Reusability Across Platform. The JSP pages uses components which are
reusable. These reusable components help keep the pages simple and run faster.
5. Easier Maintenance. Application made using JSP technology are easier to
maintain.
JSP Processing
JSP Architecture
JSP is a part of the Java platform, Enterprise Edition (J2EE), which is the java
architecture for developing multitier enterprise applications. A JSP page is executed
by a JSP engine, which is installed in a web server or a JSP enabled application
server. The JSP engine receives the request from a client to the JSP page and
generates responses from the JSP page to the client.
Response
Client Response
Request JSP engine
And Response
JSP File Component
Web server
Request
Request
The JSP engine passes the response back to the JSP page, where the data is formatted
according to the HTML design. The JSP engine and web server then sends the revised
JSP page back to the client, where the user can view the results in the web browser.
The communication protocol used between the client and server can be HTTP, or it
can be some other protocol.
JSP Syntax
Everything in JSP can be broken into two categories:
Directives
Declarations
Scriptlets
Expressions
Standard Actions
A JSP page contains scripting language and some special JSP tags that can encapsulate
tasks that are difficult or time consuming to program.
JSP Directives
Directives are instructions for JSP engine that are processed when the JSP page is
translated into a servlet. They are used to set global values such as class declarations,
methods to be implemented, output content type etc. The directives should start with
<%@ and end with %>. There are three types of JSP directives.
They are:
1. The page directive defines a number of attributes that affect the whole page.
The syntax is as follows:
<%@ page attributes %>
2. The include directive is used to insert text and code at JSP translation time.
The syntax is as follows:
3. The taglib directive declares that the page uses custom tags. Uniquely names
the tag library defining them and associates a tag prefix that will distinguish
the usage of these tags. The syntax is as follows:
JSP Scriptlets
JSP scripting is a mechanism for embedding code fragments directly into an HTML.
There are three types of scripting elements, namely scriptlets, expressions and
declarations.
Scriptlets are used to embed any piece of java code into the page. The code is inserted
into the generated servlet and is executed when the page is requested. The syntax for
a scriptlets is as follows:
<% Scriptlet source %>
Scriptlet are executed at request time, when the JSP client processes the client
request. If the scriptlet produces output, the output is stored in the JSP writer
implicit object out.
Writing a simple JSP page using Scriptlets:
Hello.jsp
<html>
<head><title> Hello </title></head>
<body>
<%
int x = 0;
for(x = 0; x < 5; x++)
{
out.println(“<h1> Hello world ! </h1>”);
}
%>
</body>
</html>
JSP Lifecycle
Expressions are used to dynamically calculate values to be inserted directly into the JSP
page. These are elements that are evaluated with the result being converted to
java.lang.String. After the string is converted, it is written to the out object. The expression
should be enclosed within <% = and %>.
An expression can be complex and composed of more than one part or expression. For
example, the following shows the date and time that the page requested:
JavaScript
“JAVASCRIPT IS A SCRIPTING LANGUAGE DESIGNED TO ADD INTERACTIVITY TO
HTML PAGES.”
How to put?
<HTML>.
<BODY>
<SCRIPT TYPE=”text/javascript”>
Document.write(“Hello World !”)
</SCRIPT>
</BODY>
</HTML>
Events
Events are actions that can be detected by JavaScript. Every element on a web page has
certain events which can trigger JavaScript functions. For example, one can use the
onClick event on a button element to indicate that a function will run when a user clicks
on the button.
Examples of events:
A mouse click
A web page or an image loading
Mouse over a hot spot on the web page.
Selecting an input box in an HTML form
Submitting an HTML form
A keystroke
Cookies
A cookie is 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.”
Creating Cookies
The “Response.Cookies” command is used to create cookies. For example, to create a
cookies named ”firstname” and assigning the value “Ashwin” to it, following command
may be used:
<%
Response . Cookies(“firstname”) = ”Ashwin”
%>
It is also possible to assign properties to a cookie, like setting a date when the cookie
should expire:
<%
Response . Cookies(“firstname”) = “Ashwin”
Response . Cookies(“firstname”) . Expires = # May 10, 2002 #
%>
Retrieve a Cookie Value
The “Request . Cookies” command is used to retrieve a cookie value. For example,
<%
Fname = Request . Cookies(“firstname”)
Response . write(“Firstname = ” & fname)
%>
Output:
Firstname = Ashwin