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

Web Development Internet Protocols

HTTP is an application-level protocol for distributed, collaborative hypermedia systems that forms the foundation for data communication on the World Wide Web. It is a generic, stateless protocol that can be used for purposes beyond the web. HTTP uses TCP/IP and default port 80 to deliver resources like HTML files and images. It provides a standardized way for clients and servers to communicate by specifying how requests are constructed and sent, and how servers respond.

Uploaded by

Devender Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Web Development Internet Protocols

HTTP is an application-level protocol for distributed, collaborative hypermedia systems that forms the foundation for data communication on the World Wide Web. It is a generic, stateless protocol that can be used for purposes beyond the web. HTTP uses TCP/IP and default port 80 to deliver resources like HTML files and images. It provides a standardized way for clients and servers to communicate by specifying how requests are constructed and sent, and how servers respond.

Uploaded by

Devender Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

HYPER TEXT TRANSFER PROTOCOL

The Hypertext Transfer Protocol (HTTP) is an application-level protocol for


distributed, collaborative, hypermedia information systems. This is the foundation for data
communication for the World Wide Web (i.e. internet) since 1990. HTTP is a generic and
stateless protocol which can be used for other purposes as well using extensions of its
request methods, error codes, and headers.
Basically, HTTP is a TCP/IP based communication protocol, that is used to deliver
data (HTML files, image files, query results, etc.) on the World Wide Web. The default
port is TCP 80, but other ports can be used as well. It provides a standardized way for
computers to communicate with each other. HTTP specification specifies how clients'
request data will be constructed and sent to the server, and how the servers respond to these
requests.

Basic Features of HTTP

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

The HTTP protocol is a request/response protocol based on the client/server based


architecture where web browsers, robots and search engines, etc. act like HTTP
clients, and the Web server acts as a server.
(a) Client
The HTTP client sends a request to the server in the form of a request
method, URI, and protocol version, followed by a MIME-like message containing
request modifiers, client information, and possible body content over a TCP/IP
connection.
(b) Server
The HTTP server responds with a status line, including the message's
protocol version and a success or error code, followed by a MIME-like message
containing server information, entity meta information, and possible entity-body
content.

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.

The Host Address


The host address is where a website can be found, either the IP address (four sets of
numbers between 0 and 255, for example 68.178.157.132) or more commonly the domain
name for a site such as www.tutorialspoint.com. Note that "www" is not actually part of
the domain name although it is often used in the host address.

The File Path


The filepath always begins with a forward slash character, and may consist of one
or more directory or folder names. Each directory name is separated by forward slash
characters and the filepath may end with a filename at the end. Here index.htm is the
filename which is available in html directory:
https://www.tutorialspoint.com/html/index.htm

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

Important Features of Browser

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.

3. Another feature of browser is to have a number of other commands readily


available through menus, icons, and buttons.

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.

6. One of the main feature of a browser is to search the information on the


current page as well as search the WWW itself.

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

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.

• Generating response by invoking a script and communicating with database


Figure 1.12: Web Server Working

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

1 Apache HTTP Server

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.

Server – Side Scripting

Introduction to the Server Side Scripting


“SERVER-SIDE SCRIPTING IS A WEB SERVER TECHNOLOGY IN WHICH A USER'S
REQUEST IS FULFILLED BY RUNNING A SCRIPT DIRECTLY ON THE WEB SERVER
TO GENERATE DYNAMIC HTML PAGES.”

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:

 CGI (common Gateway Interface)


 ASP (Active Server Pages)
 JSP (Java Server Pages)
Common Gateway Interface
“THE COMMON GATEWAY INTERFACE, OR CGI, IS A STANDARD FOR EXTERNAL
GATEWAY PROGRAMS TO INTERFACE WITH INFORMATION SERVERS SUCH AS
HTTP SERVERS.”

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.

Get the form data from


There are two methods which can be used to access the forms. These are GET and POST:

GET (in the FORM tag):


The CGI program will receive the encoded form input in the environment variable
QUERY_STRING.

POST (in the FORM tag):


CGI program will receive the encoded form input on stdin. The server will NOT send an
EOF on the end of the data, instead the user should use the environment variable
CONTENT_LENGTH to determine how much data to be read from stdin.

A simple CGI Script


A simple CGI script (A Perl program) that just prints an HTML document. It’s all same as
using HTML tags as simple. The only main part is the first line must be:
Content – type: text/html

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:

<form action=http://www/comp.leeds.ac.uk/sam-cgi/answerme” method=”GET”>

Some text in here.

It can be anything except another form.


</form>

The action attribute of the tag gives the URL of the CGI script.

Common Gateway Interface (CGI)


Example of someone making a purchase on-line:
1. When the user is ready to buy the items he selected on the Web site, he goes to a "Checkout" Web
page containing a form that asks for his name, address, etc. The page containing the form is usually
a "static" page - it looks the same for everybody.

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.

3. The CGI program then sends the user's data to a database.

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.

Common Gateway Interface (CGI)


Common Gateway Interface is a specification for transferring information between a World Wide
Web server and a CGI program. A CGI program is any program designed to accept and return data
that conforms to the CGI specification. The program could be written in any programming
language, including C, Perl, Java, or Visual Basic.

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.

CGI processing steps:

Each Step mean:


1. The web surfer fills out a form, and clicks 6. The results of the database action are then
submit. The information in the form is sent over the passed back to the database driver.
internet to the web server.
7. The database driver sends the
2. The web server "grabs" the information from the information from the database to the CGI
form, and passes it to the CGI Software. Software.

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.

ASP & JSP


Active Server Pages (ASP)
“ACTIVE SERVER PAGES OR ASP IS COMMONLY KNOWN AS A TECHNOLOGY THAT
ENABLES TO MAKE DYNAMIC AND INTERACTIVE WEB PAGES.”
ASP uses server-side scripting to dynamically produce web pages that are not affected by
the type of browser the web site visitor is using.
The default scripting language used for writing ASP is VBScript, although some other
languages can also be used like Jscript (Microsoft’s version of JavaScript).
ASP pages have the extension .asp instead of .htm, when a page with extension .asp is
requested by a browser the web server knows to interpret any ASP contained within the
web page before sending the HTML produced to the browser.
Any web pages containing ASP cannot be run by just simply opening the page in a web
browser. The page must be requested through a web server that supports ASP, this is
why ASP stands for Active Server Pages, means no server, no active pages.

VBScript
“VBSCRIPT (SHORT FOR VISUAL BASIC SCRIPTING EDITION) IS AN ACTIVE
SCRIPTING LANGUAGE DEVELOPED BY MICROSOFT.”

When employed in Microsoft Internet Explorer, VBScript is similar in function to JavaScript, as


a language to write functions that are embedded in or included from HTML pages and interact
with the Document Object Model (DOM) of the page, to perform tasks not possible in HTML alone.
Other web browsers such as Firefox, and Opera do not have built-in support for VBScript. This
means that where client-side script is required on a web site, developers almost always use
JavaScript for cross-browser compatibility.

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.

VBScript provides functions and sub-routines, basic date/time, string manipulation,


math, user interaction, error handling, and regular expressions.
Additional functionality can be added through the use of ActiveX technologies.
File system management, file modification, and streaming text operations can be achieved
with the Scripting Runtime Library scrrun.dll.

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>

Using VBScript with Forms


Before sending any data from client’s browser to the web server via forms, it is needed to
validate data at client’s side itself. VBScript can be used for the purpose very well. Once
the form is validated, the same script can be used to forward the data on to the server.

Validating The Form

The Process of validating forms involves checking the form to see if:

 All of the required data is proved


 The data provided is valid.

Checking The Form Input

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

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.

What does ASP look like?


The appearance of an Active Server Page depends on who or what is viewing it. To the
web browser that receives it, an ASP looks just like a normal HTML page. In addition to
text and HTML tags, there also exists server side scripts.
The code below shows what a real, live ASP page looks like:
<html>
<head>
<title> New Page </title>
</head>
<body>
<h1> My Welcome Page</h1>
<p> <% if Time>#12:00:00 AM# AND_ Time<#12:00:00 PM# Then %> </p>
<h2> Good Morning !!! </h2>
<p> <% if Time>#12:00:00 AM# AND_ Time<#6:00:00 PM# Then %> </p>
<h2> Good Afternoon !!! </h2>
</body></html>

The Basic Syntax Rule


An ASP file normally contains HTML tags, just like an HTML file. However, an ASP file
can also contain server scripts, surrounded by the delimiters <% and %>.
Server scripts are executed on the server, and can contain any expressions, statements,
procedures, or operators valid for the scripting language preferred to be used.

Write Output to a Browser


The response.write command is used to write output to a browser. The following
example sends the text “Hello World !” to the browser:
<html>
<body>
<%
Response.write(“Hello World ! ”)
%>
</body>
</html>
There is also a shorthand method for the response.write command. The following
example also sends the text “Hello World !” to the browser:
<html>
<body>
<%=”Hello World ! ”%>
</body>
</html>

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.

How Does ASP Works?


• ASP files are only processed when a client requests them from the server.
• There are some .dll files such as ASP.dll which contains standard objects.
• Functions are called from these dlls.
• Since these functions are previously defined and known, things can be done
with ASP are bounded.
• ASP codes do not need to be compiled.
• There exists a global.asa file which is used to specify events and global session
variables which are used for all ASP files in the server.
• Before any ASP file is processed, global.asa is processed and it defines global
events.
• The processing of an ASP file starts with the separation of ASP scripts and
HTML codes in IIS.
• Then each script code is processed.
• The HTML corresponds of these scripts are created, and injected related places.
• Final HTML codes are sent to the client and displayed by the web browser.

What can ASP do?


• The most important feature of ASP is creating dynamic pages.
• You can manage data with database operations such as getting and storing
people’s information in the Database.
• Interactive applications can be implemented, i.e. news type people like may be
displayed.
• Script codes are not sent to the client, which brings security.

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.

Handling JSP Page


JSP page may be a combination of different protocols, components and formats. A
JSP page is also a place to enter user information. A user may be asked to enter his
home, address, a word or a phrase.
The information the user enters in the form is stored in the request object, which is
sent to the JSP engine.
The JSP engine sends the request object to the component (Servlet) the JSP specifies.
The component handles the request. The request may be to retrieve certain data or
other data store. The component sends the response back to the JSP engine.

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:

 Elements: That are processed on the server.


 Template: Data are everything other than elements that the JSP engine
ignores.

Element data can be classified into the following 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:

<%@ include file = “relative URL” %>


The file that the file attribute refers to can reference a normal HTML file or
another JSP file which will be evaluated at translation time.

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:

<%@ taglib uri = “taglibrary URL prefix” %>

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

JSP life cycle can be grouped into seven phases.


1. JSP Page Translation: A java servlet file is generated from the JSP source file.
Generated servlet implements the interface javax.servlet.jsp.HttpJspPage. The
interface HttpJspPage extends the interface JspPage. This interface JspPage extends
the interface javax.servlet.Servlet.
2. JSP Page Compilation: The generated java servlet file is compiled into a java servlet
class. The generated servlet class thus implements all the methods of the above said
three (javax.servlet.jsp.HttpJspPage, JspPage, javax.servlet.Servlet) interfaces.
3. Class Loading: The java servlet class that was compiled from the JSP source is loaded
into the container.
4. Instance Creation: An instance is created for the loaded servlet class. The interface
JspPage contains jspInit() and jspDestroy(). The JSP specification has provided a
special interface HttpJspPage for JSP pages serving HTTP requests and this interface
contains _jspService().
5. jspInit( ) execution: This method is called when the instance is created and it is called
only once during JSP life cycle. It is called for the servlet instance initialization.
6. _jspService() execution: This method is called for every request of this JSP during its
life cycle. It passes the request and the response objects. _jspService() cannot be
overridden.
7. jspDestroy() execution: This method is called when this JSP is destroyed and will not
be available for future requests.

JSP Expressions (Conditional Processing)

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 %>.

While writing an expression, following points should be taken care of:

1. Semicolon cannot be used to end an expression.


2. The expression element can contain any expression that is valid according to java
language specification.

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:

Current Time : <% = new java . util . Date() %>

JSP Declarations (Declaring Variables and Methods)


JSP declarations are used to define methods or variables that are to be used in java
code later in the JSP file. The declarations get inserted into the main body of the
servlet class. It has the following form:
<% ! declarations %>
Since declarations do not generate any output they are usually used with JSP
scriptlets or expressions. For example,
<% ! int i = 0; %>
<% ! circle a = new circle(2,0); %>
A declaration element may contain any number of variables or methods.

JavaScript
“JAVASCRIPT IS A SCRIPTING LANGUAGE DESIGNED TO ADD INTERACTIVITY TO
HTML PAGES.”

A JavaScript consists of lines of executable computer code.

It is usually embedded directly into HTML pages.

It is an interpreted language (means that scripts execute without preliminary compilation).

Everyone can use JavaScript without purchasing a license.

What a JavaScript Can do?


 It gives HTML designers a programming tool.
 It can put dynamic text into an HTML page.
 It can react to events.
 It can read and write HTML elements.
 It can be used to validate data.
 It can be used to detect the visitor’s browser.
 It can be used to create cookies.

How to put?
<HTML>.
<BODY>
<SCRIPT TYPE=”text/javascript”>
Document.write(“Hello World !”)
</SCRIPT>
</BODY>
</HTML>

Objects, Properties and Methods in JavaScript


Each object has certain properties, and methods associated with it. Properties are things that
describe the object, and they include sub – objects. For example, is a person is considered to be
an object, then hair color, height, etc. are its properties or sub – objects.
Methods are things that the object can do or things that can be done to the object. One method
associated with the document object is write(). For example, the document.write() method writes
HTML to a Web page. The argument to be passed to write() method is a string of text that will be
written. For example, document.write(“Hello World!”).

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

A Cookie With Keys


If a cookie contains a collection of multiple values, this is said as the cookie has keys.
Consider the example to create a cookie collection named “user”. The “user” cookie has
keys that contains information about a user:
<%
Response . Cookies(“user”) (“firstname”) = “ADITYA VARDHAN”
Response . Cookies(“user”) (“lastname”) = “ANUBHAV AGARWAL”
Response . Cookies(“user”) (“country”) = “INDIA”
Response . Cookies(“user”) (“age”) = “22”
%>

Read all Cookies


Consider the following code:
<%
Response . Cookies(“firstname”) = “Ashwin”
Response . Cookies(“user”) (“firstname”) = “ADITYA VARDHAN”
Response . Cookies(“user”) (“lastname”) = “ANUBHAV AGARWAL”
Response . Cookies(“user”) (“country”) = “INDIA”
Response . Cookies(“user”) (“age”) = “22”
%>
Assuming the server sent all the cookies above to a user. To read the cookies the user
can use the following code:
<html>
<body>
<%
Dim x,y
For each x in Request . Cookies
Response.write(“<p>”)
if Request . Cookies (x) . HasKeys then
for each y in Request . Cookies (x)
response.write (x & “:” & y & “=” & Request . Cookies (x) (y))
response.write (“<br />”)
next
else
Response . Write (x & “=” & Request . Cookies (x) & “<br />”)
end if
response. Write (“</p>”)
next
%>
</body>
</html>
Output:
Firstname = Ashwin
User:firstname = ADITYA VARDHAN
User:lastname = ANUBHAV AGARWAL
User:country = INDIA
User:age = 22

You might also like