Web Technologies Unit 1-5 PDF
Web Technologies Unit 1-5 PDF
Web Technologies Unit 1-5 PDF
WEB TECHNOLOGIES
UNIT-I
Internet Principles: Introduction to Internet - Client Server Model- Protocol - Internet IP Address-
Domain Name - Internet Services - Electronic Mail - World Wide Web - Internet Security - E-
Commerce- EDI.
UNIT –II
Introduction to HTML: HTML Tags - HTML Documents - Headings - Hyperlinks using Anchor
Tag- Formatting Characters - Font - Images and Pictures - Listing - Tables in HTML Tags –
Frameset Definition - Fame Definition- Nested framesets - HTML Forms - Elements of a form use
Tags.
UNIT –III
UNIT-IV
Server Side Script with JSP: Client Responsibilities -Server Responsibilities - Introduction to JSP –
JSP Architecture - JSP Servers - JSP Tags - Request Object - Response Object - JSP Page.
UNIT – V
JSP with JDBC: Creating ODBC Data Source Name - Introduction to JDBC -Telephone Directory
with JDBC - Servlet Environment and Role - Protocol Support - HTML Support - Servelt Life
Cycle -HTML to Servlet Communication.
TEXT BOOK
C.Xavier, "Web Technology and Design", 1st Edition, New Age International, 2011.
REFERENCE BOOK
1. H.M.Deitel, P.J.Deitel, "Internet and World Wide Web - How to Program", 3rd Edition, Pearson
Publication, 2006.
UNIT-I
Internet Principles: Introduction to Internet - Client
Server Model- Protocol - Internet IP Address-Domain
Name - Internet Services - Electronic Mail - World
Wide Web - Internet Security - E-Commerce- EDI.
Internet Principles
In 1984 William Gibson in his scifinovel Neuromancer coined the term Cyberspace. It
refers to the nonphysical terrain created by computer systems.
Online systems, for example, create a cyberspace within which people can communicate
with one another (via email), do research, or simply window shop.
Like physical space, cyberspace contains objects (files, mail messages, graphics, etc.) and
different modes of transportation and delivery.
Unlike real space, exploring cyberspace does not require any physical movement other
than pressing keys on a keyboard or moving a mouse.
Some programs, particularly computer games, are designed to create a special
cyberspace, one that resembles physical reality in some ways but defies it in others.
In its extreme form, called virtual reality, users are presented with visual, auditory, and
even tactile feedback that makes cyberspace feel real.
The dreams of William Gibson is becoming a reality in the Internet world.
Using a device called modem as shown in Figure 1.2. So, through rooting two factors decide the
characteristics of the Internet services.
■ Modem
■ Connectivity for communication
Internet User
1.1.1 Modem
Short for modulator-demodulator. A modem is a device or program that enables a computer to transmit
data over, for example, telephone or cable lines.
Computer information is stored digitally, whereas information transmitted over telephone lines is
transmitted in the form of analog wave.
Fortunately, there is one standard interface for connecting external modems to computers called
RS 232.
Consequently, any external modem can be attached to any computer that has an RS 232 port,
which almost all personal computers have.
There are also modems that come as an expansion board that you can insert into a vacant
expansion slot.
These are sometimes called onboard or internal modems.
While the modem interfaces are standardized, a number of different protocols for formatting data
to be transmitted over telephone lines exist.
Some, like CC1TT V.34, are official standards, while others have been developed by private
companies.
Most modems have built in support for the more common protocols—at slow data transmission
speeds at least, most modems can communicate with each other.
At high transmission speeds, however, the protocols are less standardized.
Characteristics of a Modem
Aside from the transmission protocols that they support, the following characteristics distinguish one
modem from another:
1. Speed of transmission
At slow rales, modems are measured in terms of baud rates.
The slowest rate is 300 baud (about 25 characters per second—cps).
At higher speeds, modems are measured in terms of bits per second (bps).
A fast modem transmits at 57,600 bps, although they can achieve even higher data
transfer rates by compressing the data.
Obviously, the faster the transmission rate, the faster you can send and receive data.
Note, however, that you cannot receive data any faster than it is being sent.
If, for example, the device sending data to your computer is sending it at 2,400 bps, you
must receive it at 2.400 bps.
It does not always pay, therefore, to have a very fast modem. In addition, some
telephone lines are unable to transmit data reliably at very high rates.
2. Modes supported
Many modems support a switch to change between voice and data modes.
In data mode, the modem acts like a regular modem.
In voice mode, the modem acts like a regular telephone.
Modems that support a voice/data switch have a built in loudspeaker and microphone for voice
communication.
3. Auto-answer
An auto-answer modem enables your computer to receive calls in your absence.
This is only necessary if you are offering some type of computer service that people can call in
to use.
4. Data compression
Some modems perform data compression, which enables them to send data at faster rates.
However the modem at the receiving end must be able to decompress the data using the same
compression technique.
5. Flash memory
Some modems come with flash memory rather than conventional ROM.
Which means that the communication protocols can be easily updated if necessary.
6. Fax capability
Most modern modems are fax modems, which means that they can send and receive faxes.
CCITT has defined many important standards for data communications, including the
following:
Group 3: The universal protocol for sending fax documents across telephone lines. The Group 3
protocol specifies CCITT T.4 data compression and a maximum transmission rate of 9,600
baud. There are two levels of resolution: 203 by 98 and 203 by 196.
Group 4: A protocol for sending fax documents over ISDN networks. The Group 400 protocol
supports images of up to 400 dpi (dots per inch) resolution.
V.21: The standard for full-duplex communication at 300 baud in Japan and Europe. In the
United States, Bell 103 is used in place of V.21.
V.22: The standard for half-duplex communication at 1,200 bps in Japan and Europe. In the
United States, the protocol defined by Bell 212A is more common.
V.22bis: The worldwide standard for full-duplex modems sending and receiving data across
telephone lines at 1,200 or 2,400 bps.
V.29: The standard for half-duplex modems sending and receiving data across telephone lines at
1,200, 2,400, 4,800 or 9,600 bps. This is the protocol used by fax modems.
V32: The standard for full-duplex modems sending and receiving data across phone lines at
4,800 or 9,600 bps. V.32 modems automatically adjust their transmission speeds based on the
quality of the lines.
V32bis: The V.32 protocol extended to speeds of 7,200, 12,000, and 14,400 bps.
V34: The standard for full-duplex modems sending and receiving data across phone lines at up to
28,800 bps. V.34 modems automatically adjust their transmission speeds based on the quality of
the lines.
V.42: An error-detection standard for high-speed modems. V.42 can be used with digital
telephone networks. See MNP for a competing standard.
V.42bis: A data compression protocol that can enable modems to achieve a data transfer rate of
34.000 bps.
V.90: The standard for full-duplex modems sending and receiving data across phone lines at up
to 56.600 bps.
X.25: The most popular packet-switching protocol for WANs.
X.400: The universal protocol for e-mail. X.400 defines the envelope for e-mail messages so all
messages conform to a standard format.
X.500: An extension to X.400 that defines addressing formats so all e-mail systems can be linked
together.
Basic Rate (BRI) ISDN that consists of two 64Kbps B-channels and one D-channel for
transmitting control information.
Primary Rate ISDN. In the United States of America and a few other countries this type of
ISDN consists of 23 B-channels and one D-channel. In the Europe these have 30 B-channels
and one D-channel.
The original version of ISDN employs baseband transmission. Another version, called BISDN,
uses broadband transmission and is able to support transmission rates of 1.5 MBPS.
BISDN requires fiber optic cables and is not widely available at present. The baseband and
broadband transmission are discussed.
1.3 Protocol
A protocol is a program written as per mutually accepted standard that two computers use to
communicate with each other.
Computers use protocols (protocol programs) to format consistently their messages so that
other computers can understand them, acknowledge the receipt of messages, indicate that
they are finished sending a message and so on.
In the network when one computer requests for the service of another, it is called a client.
In order to establish the needed connectivity, both the client machine and the server machine
must have a common protocol program. This is illustrated in Figure 1.3.
In short a protocol is an agreed upon format for transmitting data between two devices.
At the destination the IP verifies the labels and passes them to the TCP.
The TCP (at the destination) checks if all the segments have been received.
If any of the segments are missing it informs this to the source TCP and requests the segment to
be sent again. It is called retry.
After verification, the TCP assembles the message from these data segments and supplies to the
destination program
Packet Switching (Routing)
Routing (Packet Switching) refers to the job of transferring the data packets (IP datagrams) to an
appropriate computer.
A special computer that does routing is called router.
We have already seen that Internet is a network of networks.
So when a packet of data (IP datagram) starts from a computer, it is submitted to the router of
the network to which the computer belongs to.
The router verifies the IP address of the destination.
The destination network may not be directly reached.
The router finds the next network to which the datagram must be submitted and does it.
Similarly the datagram passes several routers and finally reaches the final destination network.
Every router uses routing tables and routing algorithms to accomplish the job.
The routing algorithm will choose the next network to which the datagram may be routed
depending upon the data traffic and the shortest route.
Datagrams of the same message may travel through different routes to reach the final
destination.
But finally the TCP protocol takes care of verifying if all the datagrams have reached. For
example, suppose a Computer Cl in network A wants to communicate with a Computer C2 in
network F as shown in Figure 1.5.
When a message has to be sent from A to F, the message is disassembled into IP datagrams.
Some datagrams may travel in the path C1ACDFC2 whereas some may travel through Cl
ABEFC2. However, C2 verifies if all the datagrams have reached.
Then it assembles the message and supplies to the application program in C2.
tracert<domain>
For example, we can type tracert lsu.edu
Router
A router is a special computer that manages the traffic from network to network. The router
determines the path of travel for a datagram in TCP/IP.
Routers keep track of the next computer to which the datagram has to hop.
They use routing tables and routing algorithms to do routing.
In Windows NT. we can see the IP address of the router in our network by running the
WINIPCFG.EXE program.
When we run the program click more info and then select PPP Adapter in the dropdown list.
In the middle of the dialog box the IP address of the router is shown in the field Default
Gateway.
This is the IP address of the router to which your computer will send a TCP/IP datagram when it
is addressed to a computer that is not on your local network. This is illustrated in Figure 1.6.
1.3.7 Bluetooth
Bluetooth refers to a short range radio technology aimed at simplifying communications among
Net devices and between devices and the Internet.
It also aims to simplifying data synchronization between Net devices and other computers.
Products with Bluetooth technology must be qualified and pass interoperability testing by the
Bluetooth Special Interest Group prior to release.
■ ca—Canada
■ th—Thailand
Because the internet is based on IP addresses, not domain names, every Web server requires a
Domain Name System (DNS) server to translate domain names into IP addresses as shown in
Figure 1.7.
Domain Name Server Internet Host
ISP
Figure 1.7 The Role of DNS
http://www.stxaviers.com/index.html
The domain the cookie is valid for—this takes the path parameter one step further.
This makes the cookie accessible to pages on any of the servers when a site uses
multiple servers in a domain.
The need for a secure connection—this indicates that the cookie can only be
used under a secure server condition, such as a site using SSL.
Both Netscape and Microsoft Internet Explorer (IE) can be set to reject cookies if the user prefers.
-----------------------UNIT-I COMPLETE-------------------------
UNIT-II
Introduction to HTML
Html is the basic tool for designing a web page.
HTML is the acronym for Hypertext Markup Language.
It is a documentation language to mark the headings, title, table and forms.
IBM wanted to set a documentation system in which we can mark the title, headings, paragraphs
and font type selections in the 1980s.
They came out with a set of markup system called it General Mark Up Language (GML). In
1986, International Standardizing Organization (ISO) took up this concept and standardized it as
Standard Generalized Mark Up Language (SGML).
In 1989 Tim Berners Lee and his team in the European Laboratory for Particle Physics (CERR)
designed the present form of the documentation language and called it HTML.
Most of the tags have end tag. which begins with </. For example </hl> is the end tag
for <hl>.
A tag may have some attributes. Attributes are the properties of the tag. For example, consider
the <hr> tag. This tag is for drawing the horizontal ruling (horizontal line).
This tag contains the following attributes.
2.3 Headings
Headings can be created with tags hl, h2,...h6. Hl will make a bigger heading, h2 will make a
smaller one and h3 will make still a smaller heading and so on. For example, if you want the
name of your company (Innovative Educational Media Ltd.) to appear as a big heading, we type
as follows
<hl>Innovative Educational Media Ltd</hl>.
Here the anchor tag <a> has an attribute href. This attribute specifies the name of the document to be
opened.
For example, a HTML file travel. html is shown below. It contains details about the travel made.
<html>
<head>
<title>Travel in December 2002 </title>
</head>
<hl>Travel Details </hl>
<hr>
<br>
<h3>December 28, 2002 <a href**us.html*> United States of America </a> </
h3>Quarterly Meeting with Bank of America
<br><h3> December 29, 2002 <a href= 'Canada.html* >Canada </a></h3>
Meeting with Brach office Managers<br>
</body>
</HTML>
When this file is opened using an Internet browser we get the page shown in Figure 2.3.
In this page United States of America is a hot text. When this is clicked, it will open us .html.
2.8 Listing
This section introduces two more tags <ol> and <ul> that lists a set of items either with serial
numbers or with bullets.
They are called Ordered and Unordered lists.
Instead of numerals, we can have such as A, B, C, or a, b. c Etc or roman letters in the ordering of the
listed items.
This is specified by the type attribute in <ol> tag. The symbols used with type attribute are shown in
Table 2.3.
2.9 Tables in HTML Tags
In HTML the beginning of a table is marked by <table> tag and the end is marked by
</table> tag.
If we want a border for our table, we must give the beginning tag as
<table border>
If we want a bigger border we can also give numbers to represent the size of the border. For example,
<table border « 5>
<html>
<head>
<frameset cols=*52,4>
<frame name=*f1• src=•http:\\localhost:8080\forexl.jsp*>
<frame name="f2• src=*http:\\localhost:8080\servlet\Forex*>
</frameset>
</html>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</frameset>
</html>
method="post”
This is the recommended protocol. With the post method, the information from the user is put into
the data stream of the HTTP, and the backend program can read the data as input through the
"standard input' data stream.
In the case of method = 'get', the data received in the form are placed at the end of URL.
If the form is very big and gets a number of input, the 'get' method causes the URL to be very
long. So, the method « 'get' option is often discouraged.
Multiple attribute
The name attribute assigns a name for the variable, which will hold the selected choice.
<select name=“nameBox“*
<option
value=“1‘>Aparna</option*
<option
value=“2’>Nithya</option*
<option
value=”3’Priya</option*
</select>
In the dropdown list we normally select one of the items.
There are certain cases in which the user can be given a freedom to select more than one of the options.
This is provided by the multiple attribute in the select tag.
cselect name « townsvisited multiple « “multiple* *
2.14.4 Checkbox
The following is a HTML document that shows a form with several checkboxes.
<html>
<head>
</head>
<body>
<h3>Please select your computer configuration<br></h3>
<h4 >
<input types’checkbox"
name «=’computer ’ values*CPU Intel P4 1.8GHz ’ >Intel P4 1.8GHz<br>
<input types’checkbox*
name=’computer" values’HDD 40 G3’>With 40 GB HDD<br>
<input type’checkbox"
name’computer" value*l5 inch color Monitor’>With Monitor<br>
<input types’checkbox’ .
name=’computer" value’1.44MD FDD">With
FDD<br>
<input type’checkbox"
name’computer" value’CD ROM Drive’>With CD ROM Drive<br>
<input type’checkbox"
name=’computer" value’Printer’>With Printer<br>
<input type’text’ nameOrder" size=’50’>
<input type•"button" name’test’ value"Order Please’>
</h3>
</body>
</html>
The following HTML document shows two text fields and a button.
<html>
<head><title>Factorial</title>
</head>
<body>
<form>
<hr><br>
<hl align='center*><marquee> Factorial </marquee></hl>
<pre>
<center>
Enter the number : <input type^text name«a>
<br>
The Factorial is : cinput type=text name=b>
<br><br>
<input type=button value='Find the Factorial' >
</pre>
</form>
</body>
</html>
The following HTML code creates a text area as shown in Figure 3.11.
<h2>Type your remarks here and press Proceed button</h2>
<textarea name = "remark* rows « *5* columns =*25">
</textarea>
<input type=button value="PROCEED*>
Exercises
The date of birth has three list boxes, for day, month and year.
The date list contains the dates from 1 to 31.
The month list contains JAN, FEBDEC. The year list contains the years from 1950 to 2000.
---------------------------------------UNIT-II COMPLETE------------------------------------
UNIT -III
JavaScript : Data Types - Variables - Operators - Conditional statements
using Javascript – Document Objects - Image Objects using Javascript -
Forms and Elements - Event Handling - Browser Object - Submit Event
and Data Validation -Parseint() Function - ParseFloat() Function -
Recursive Function.
JavaScript
Though JavaScript is a free flow language it is vital to know the basic framework of the
language.
These fundamental elements of the language are similar to that of any other language.
But for the sake of completeness, this Chapter deals with variables, data types, operators,
expressions and statements.
3.1 Data Types
Due to the use of JavaScript in interactive web design, the main focus of the language is not
processing of numeric data for precision.
However the language supports Numeric. Boolean and String data.
Apart from the above three types. Object is another important data type supported.
As a open standard the Null Data and Undefined data types are also supported.
3.1.1 Numbers
The integer and floating point numeric data are called numbers.
A number can be positive, negative or zero. Integers can be represented in decimal, octal and
hexadecimal form.
The octal integer begins with a zero and hexadecimal integer begins with Ox or oX.
The following are some valid integers.
45 Decimal value 45
1 Decimal value 0
-25 Decimal value 25
-015 Octal value (—15)8
OX2A Hexadecimal value(2A)
Floating point numbers can be represented either in decimal form or exponent form.
The following are some valid floating point numbers.
0.78
-10.2
0.25e4
-O.8E3
3.1.2 Boolean
JavaScript considers True or False values as Boolean values.
In comparison 0 is considered as false and any nonzero value as True.
3.1.3 String
A String is any list of characters given within single or double quotes.
3.1.4 Objects
JavaScript is an Object Oriented language. It is possible to define an object of a class.
For example an object of an Employer class can be created using new operator as follows:
x = new Employee(“Raman*,45);
3.2 Variables
The name of the location where a data value is stored is called variable.
For example, when we say age = 45. The value 45 is the data value.
It is stored at a location called age.
So, age is the variable.
45Age
In other words, the variable is the data reference.
In JavaScript, no declaration is necessary to specify the type of data stored.
However the scope of the variable is an important aspect to be discussed here.
A variable may have either global scope or local scope.
A variable by default is having global scope.
If a variable has to be defined in local scope, define with var keyword.
3.2.1 Global Scope
A variable having global scope can be accessed from any function on the page.
If a value is simply assigned to a variable, it is of global scope.
age = 45;
If the variable age is created as above, it means that it is having global scope.
3.2.2 Local Scope
Temporary variables having scope only inside a function are said to have local scope. Local
Variables are defined using var statement.
For example, consider the following:
function
sum(a,b) (
var total=0;
total + a+b;
return(total
>;
}
In the above function, total is defined using var statement.
So, it has local scope.
This means that it cannot be referred from other functions of the JavaScript page.
3.3 Operators
JavaScript permits almost all the common operators of any language.
They are listed below:
3.3.2Boolean Operators
&& A
ii Or
! Not
3.3.3 String Concatenation
Concatenation
For example,
Rama' + 'Krishnan*gives
RamaKrishnana = 'Kalyana'
b='Raman’
c=a+b
}
</8cript>
</head>
<body>
<form name«zsd*biodata_form* onsubmit«*return validate()*>
<h3>Enter your Age
please..</h3> cinput
type=*text* name=*age*>
<input type="submit” value=*Submit Age*>
</form>
</body>
</html>
The output is shown in Figure 4.1.
>
while! condition)
The statements between do and while are executed repeatedly until the condition
becomes false.
The for-in loop is used to repeat a set of statements for each property of an object or each
element of an array.
The following is the general format:
for (var v in object)
<
----------
---------
--------
>
If object referred above has n properties , the statements are executed n times with v assuming
these n values.
The above function changes the background color to the specified color C.
This function can be called at any specified event and the color changed.
The output of the color document is shown in Figure 5.4.
In the document the images are referred by the array images(O), images11,
...etc.. The above statements change the size of images [0] into width.300 and height350.
If the images are given some names then we can use the name in the place of images [0].
For example, consider the following in a HTML document.
<img sre 'logol.gif* width = 100 height=200 >
The image is loaded from the file logol.gif. So, in a Javascript Program we can refer to this image
as document images [ 0 ]. The following statements can be used to change the width and
height to 300 and 350 respectively.
document.images[01.width << 300
document.images[0].height « 350
This form has seven elements. JavaScript represents them using an array elements [ ]. Table 5.4.1
shows the reference details of each of the elements.
In a JavaScript program if we want to reset the value of Name input Text field with a
string “Type Your Name”, we will code as follows:
document.forms[01 elements[0].value=*Type Your
This changes the value of String in the Text Area to 'Address Please* .
A document may have several forms. They are referred to by the array forms [ ].
For example, if a document has three forms they are referred by forms[0], forms[1]
and forms [ 2 ]. This is illustrated in the following example.
Screen OK Button Capacity Text OK Button Capacity Text Select Box OK Button
size Text Field Field
Field
Figure 5.9 The Tree Representation of the Objects in the Document
For example a text field for Television Screen Size in the first form is referred as
document.form[0).elements[0]
If we want to make the width as 300 and height as 350 we can write as follows:
document.complogo.width = 300
document.complogo.height = 350
If this image is the first image in the document, we can also refer to the image as images[ 0 ]
instead of its name. So, this can also be written as
document.images[0].width = 300
document.images(0].height = 350
The HTML document created in Example 5.3.1 shows the image of the CEO. The image can
be given a name CEO as shown below:
< img src « 'ceoold.gif* name » CEO width = 160 height = 100 border = 1 >
Now the name CEO can be used to modify the height and width as illustrated in the following
document.
Consider the HTML document illustrated in Example 5.4.1. Each object in the document can be
assigned a name. Let the three forms be given the names as shown in Table 5.4.2 :
The portion of the html page for the Television Order Form is written as follows:
■ The capacity text field in Washing Machine order Form can be named washcapacity.
■ The capacity text field in Refrigerator Order Form can be named ref capacity.
■ The Select box in the Refrigerator Order Form can be named ref type.
The HTML document is rewritten with the above names as follows:
<html>
<head>
<title> Order form </title>
<script language*•JAVASCRIPT*>
<! —
function alertTV()
<
size=document.tvform.tvsize.value
alert('You want to order a television of size = ”+size)
}
3.7.2 Check Box Element
This section illustrates the use of check box to select System configuration.
The page designed here shows a Check Box, a Text box and Submit button.
In this document the user selects the Check box in order to select the system
configuration.
Once the user clicks order please button the selected configurations appears in the text
box.
The HTML document follows:
The output is shown in Figure 5.11
The reader must note that this method of handling foreign exchange conversion is an inefficient
one as the values are dynamic.
However, we use this method here because our objective here is to illustrate the elements of a
form.
The form is given the name Forexform.
< form name « forexform>>
After entering a value in this input text field, when the user clicks the radio button
“US Dollar” this value is converted into US Dollar and the value is shown in an alert
message.
The complete HTML/Javascript code is given below:
The output is shown in Figure 5.13.
When the above array is created, we can refer to the numbers as phone [0].
phone [1], phone [2] etc. For example, phone [0 ] refers to the phone number of
Apama 6184723.
We must now write a Javascript function getnumher (f)lo display the phone number.
The input parameter f is the form of this document.
The form has format shown in Figure 5.15.
■ A key is pressed.
■ Mouse is dragged.
FZif user clicks the left button of the (X. Y) co-ordinate of the point of click with
mouse. reference to the screen.
ASCH value of the key pressed.
77ie user presses a key.
(Con id.)
3.8.2 Double Click (dblclick) Event
A dblclick event occurs when the user double clicks the left button of the mouse. In the
following example, an alert message is thrown when the user double clicks anywhere in the
document.
<html>
<h4>Web Technology book by Dr. C. Xavier<br>
<h5> This is a sample page to illustrate Double click
event.<br><br> Double click in the document </h5>
<body ondblclick='alert(‘Hi..You have done a Double Click’)”>
</body>
</html>
3.8.3OnHelp Event
A Onhelp event occurs when the user presses the Fl key. Let us see an example to illustrate
this.
<html>
<h4>Web Technology book by Dr. C. Xavier<br> </h4>
<h5> This is a sample page to illustrate OnHelp... Press Fl key for help
<br><br> </h5>
<body>
<h5>Type the city code </h5>
<input type«”text” name=”Citycode”
onHelp=”alert('Citycode Chennai-CH \n Delhi-DL \n Mumbai-MB \n')”>
</body>
</html>
<head>
<
document.forms[0].college.select() document.forms[0].college.focus()
</script>
</head>
<body>
<h2>Please click the button and then type the name of the college</h2>
<form>
<input type*"text" name*"college* size*"30’ value*"St.Xavier's College">
<input type«"button" value»."Enter College" onclick*"setfocus () ">
</form>
</body>
</html>
Notice that Javascript is a free form language and so we can also write
w = f.weight.value
However if the user types an invalid text value then w accepts the text value and w becomes a
string variable.
So it is safe to use parseFloatO function whenever float value input is given.
If one closely investigates this calculation the following fact can be found.
Factorial (n) = n* Factorial (n-1)
In other words, multiplying the factorial of (n•1) gets factorial of a number n by n. This
leads to the following definition.
Factorial (n) =1 if n=0 or n=l.
= n * Factorial (n-1) if n>l.
We can write this function in Javascript as follows:
DataValidation:
Does the data validation as defined in the Javascript.
For example if a field of a form is an input of age the client side Javascript validates
the age to have a meaningful value
Service Request:
The Client makes a request to the Server for appropriate service.
The technologies involved in the client side operations are HTML and Javascript. In the place
of JavaScript.
VBScript or JScript can also be used.
The user goes to a web site made using JSP. The user goes to a JSP page (ending with
.jsp). The web browser makes the request via the Internet.
The JSP request gels sent to the Web server.
The Web server recognizes that the file required is special (.jsp). therefore passes the
JSP file to the JSP Servlet Engine.
If the JSP file has been called the first time, the JSP file is parsed, otherwise go to step 7.
The next step is to generate a special Servlet from the JSP file. AE the HTML required is converted to
print In statements.
The Servlet source code is compiled into a class.
The Servlet is instantiated, calling the init and service methods.
HTML from the Servlet output is sent via the Internet.
HTML results are displayed on the user's web browser.
o Open the command Prompt and go to the bin folder of the web server. C:\Java
Web Server 2.0\bin.
o Type the command http d and press enter This is illustrated in Figure 7.3
4.5.2 Placing the JSP File
The JSP file must be created and stored in the following folder
C:\JavaWebServer2.O\public_html
Consider the following JSP file.
<html>
<head>
<title>My first JSP page
</title>
</head>
<body>
<%”page language^java” %>
<h3>
<% out.printin(“Web Technology book by Dr. C. Xavier”); %>
</h3>
</body>
</html>
We must store this file as book, jsp in C:\javawebserver2.0\public_html folder.
In order to open the JSP file, open the Browser and type the following in the address
field.http: / /localhost: 8080/book. jsp. This is illustrated in Figure 7.4
Figure 7.4 The First JSP Page
Note:
If the Web Server is running on a different machine, http://localhost:8080 must be replaced by
the URL of the Web Server Machine.
Here is a modified version of our JSP from previous section, adding in a Scriptlet.
<%0 page import”java.util.” %>
<HTML>
<BODY>
<%System.out.printlnt “Web Technology Book by Dr. C. Xavier” );
java.util.Date d « new java.util.Date();System.out.println(d);%>
Hello! The Date and time now: <%« d %>
</BODY>
</HTML>
Note:
If you run the above example, you will notice the output from the 'System.out printin” on the server log
and not in the Browser.
By itself a scriptlet does not generate HTML.
This is shown in Figure 7.5 and Figure 7.6. If a scriptlet wants to generate HTML, it can use a
variable called “out”.
This variable does not need to be declared.
It is already predefined for scriptlets, along with some other variables.
The following example shows how the scriptlet can generate HTML output.
<%@ page import**java.util.** %>
<HTML>
<BODY>
<%System.out.printlnt “Web Technology Book by Dr. C. Xavier”);
java.util.Date d « new java.util.Dated ;
System.out.println(d);%>
Hello! The Date and time now:
<%
out.println(d);
%> </BODY>
</HTML>
Example
<%!
private int counter =0 ;
private String get Account I int accountNo);
%>
This tag allows the developer to embed any Java expression and is short for out
.printin ().
A semicolon (; ) does not appear at the end of the code inside the tag. For example, to show the
current date and time.
Date: <%= new java.util.Date () %>
Syntax
Here <%%> tags are scriplets tag and within it, we can place java code.
4.6.5 Action
JSP actions use the construct in XML syntax to control the behavior of the servlet engine.
We can dynamically insert a file, reuse the beans components, forward user to another
page, etc. through JSP Actions like include and forward.
Unlike directives, actions are re-evaluated each time the page is accessed.
Syntax:
In this tutorial, you will learn about Actions. Actions are used for controlling the behavior
of servlet engine.
4.6.5.1 jsp:useBean:
This action name is used when we want to use beans in the JSP page.
With this tag, we can easily invoke a bean.
Syntax
4.6.5.2 jsp:include
It also used to insert a jsp file into another file, just like include directive.
It is added during request processing phase
Syntax
4.6.5.3 jsp:setProperty
Syntax:
4.6.5.4 jsp:getProperty
4.6.5.5 jsp:forward:
Syntax:
<jsp:forward page="value">
4.6.5.6 jsp:plugin:
It is used to introduce Java components into jsp, i.e., the java components can be either an
applet or bean.
It detects the browser and adds <object> or <embed> tags into the file.
Syntax:
4.6.5.7 jsp:param:
Syntax:
<jsp:params>
<jsp:param name="val" value="val"/ >
</jsp:params>
4.6.5.8 jsp:body
This tag is used to define the XML dynamically i.e., the elements can generate during request
time than compilation time.
It actually defines the XML, which is generated dynamically element body.
Syntax:
<jsp:body></jsp:body>
4.6.5.9 jsp:attribute
This tag is used to define the XML dynamically i.e. the elements can be generated during request
time than compilation time
It actually defines the attribute of XML which will be generated dynamically.
Syntax:
<jsp:attribute></jsp:attribute>
4.6.5.10 jsp:text
Syntax:
<jsp:text>template text</jsp:text>
4.6.5.11 output:
Syntax:
In this example the JSP request variable is used to obtain information from the request as
sent by the browser.
<% String agestring = request.getParameter('age'); %>
Age of the person » <%= ageString %>
This code scriptlet is storing the parameter age in the string agestring.
In this example we illustrate the use of getParameterO method of the request object. Consider the
following HTML form, which has a text field for typing the name.
<html>
<head>
</head>
<body>
<formname='phoneEnquiry' action='http://prof2:8080/PhoneDirectory.jsp' cinput
type='text' name='name'>
Cinput type='submit' value='Find Phone Number*>
</form>
</body>
</html>
The user can type the name of the person whose phone number is to be found.
Notice that the name of the text field is “name”.
When the user types the name and presses the submit button “Find Phone Number" the browser
submits the request to the Web Server to service the request with the help of the JSP page
PhoneDirectory JSP.
Now we can send the name given and the phone number ph to the browser as
follows:
out.printIn('<center>'”namegiven”'<br>');
out.printin('Name :'”namegiven” '<br>');
out.printIn('Phone :’ph+'<br>');
For simplicity we have not fully dealt with the case when the name doesn’t match with
the five known names.
The complete JSP PhoneDirectory. jsp is shown below:
<html>
<head>
<title>Phone Directory</title>
</head>
<body bgcolor=bisque text«black>
<hrxh2>
<pre>
<%
int ph=0;
String namegiven=request. get Parameter ('name');
String[]name « {'Aparna', 'Uma', 'Anitha', 'Kamal',
'Rajini'};
int[]phone={26549876, 24356786, 27856456, 21345244, 27856432};
for (int i«0;i<5;i*+)
if (namegiven.equals(name[i]))
{
ph=phone[i];
}
out.printin('<center>””namegiven<br>');
out.printin('Name :'>namegiven>'<br>');
out.printin('Phone :'+ph+'<br>'};
%>
</h2>
</pre>
<br><hr>
</body>
</html>
The output is shown in Figure 4.10 for the input name Uma.
The following JSP fragment contains mixed template text and scriptlets.
<% if (Math.random() < 0.5) { %>
Tossing the coin Result: <B>Head</B>
<% ) else { %>
Tossing the coin Result: <B>Tail</B>
<% > %>
This will get converted to as follows:
if (Math.random() < 0.5)
out.printIn('Tossing the coin Result:<B>Head</B>);
else
out.println(“Tossing the coin Result: <B>Tail</B> “);
)
%>
Your registration was received at <%= new java.util.Date() %> We shall send you
the copy shortly.
Thank you for your interest. Please find attached the Content pages of the book.
<blx:emailAttach file=’C:\\contents.txt’
contentType+”text/plain”name”'contents.txt/>
</blx:email>
<!— Also write out some HTML —>
Thank you.A confirmationemail has been sent to <%* email %> <% } %>
</BODY>
</HTML>
6. Create a Form with appropriate background color, font settings, four choice boxes and
one Text Field for Amount. Load the Choice boxes with the values countryName [ ] and
currency[] as follows:
6.1 Load the Choice box fromCountry with the values in countryName!).
6.2 Load the Choice box fromCurrency with the values in currency!).
6.3 Load the Choice box toCountry with the values in countryName [ ].
6.4 Load the Choice box toCurrency with the values in currency I ].
7. Based on the user selection the values of fromCountry and toCountry are passed to the
Servlet as hidden variables from and to along with the amt (fromAmount).
----------------------------------------UNIT-IV COMPLETE-------------------------------------------
UNIT – V
JSP with JDBC: Creating ODBC Data Source Name - Introduction to JDBC -
Telephone Directory with JDBC - Servlet Environment and Role - Protocol Support -
HTML Support - Servelt Life Cycle -- HTML to Servlet Communication.
1. Application layer
2. Database access
Consider a MS Access Database with name forex.mdb. Assume that it has the structure a shown
in Figure 5.2.
Figure 5.2 Table Forex
1. Go to control panel
2. Go to Administrative tools
5 In the Create new Data Source Window select Microsoft Access Driver and click Finish. The
ODBC Microsoft Access setup window appears. In this window type the name of the Data Source
(forex) and click select button. Now the Select Database window appears. Now select the database
forex.mdb and click OK. Now the ODBC Microsoft Access Setup window appears showing the
database selected.
6. Give a DSN name, click ok
Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
con =DriverManager.getConnection (“jdbc:odbc:forex","","");
Telephone Directory
We have a HTML page that has a Input Text field and a Submit button.
When the user enters the name of the person and clicks the submit button the HTML page
submits a request to a JSP page.
The JSP page called phone.jsp receives the request, extracts the name from the request object,
opens the database table and gets the phone number and sends it to the browser.
1. Extract the name of the person from the request object. This is done as follows:
String s= request.getParameter ("n");
Here the name n is got from the request object and stored as a String object s.
2. Create the JDBC Connection to the ODBC data source phonedir3. (phonedir3 is a odbc data
source which had already been created). The JDBC Connection is established using the
following Java code:
Class. forName("sun.jdbc.odbc.jdbcOdbcDriver");
cn=DriverManager.getConnection
"jdbc:odbc:phonedir3","","");
3. Create an appropriate SQL statement as a PreparedStatement object. In our case the SQL query must
be "Select * from phone where name=?". In this the filler (?) must be filled by the content of s created
in step 1. We write the Java code as follows:
ps-cn.prepareStatement("select * from phone where name=?"); ps.setString (1,);
Java Servlet
In designing an Internet based application, the intermediate server runs a program to offer useful
middle-ware services between the client and the server. They are called Servlets in Java.
A servlet is a JavaTM component that can be plugged into a Java-enabled web server to provide
custom services.
These services can include:
New features
Runtime changes to content
Runtime changes to presentation
New standard protocols (such as FTP)
New custom protocols
Servlets are designed to work within a request/response-processing model.
In a request/ response model, a client sends a request message to a server and the server
responds by sending back a reply message.
Requests can come in the form of an
I HTTP URL
FTP URL or
a custom protocol.
The request and the corresponding response reflect the state of the client and the server at the
time of the request.
Normally, the state of the client/server connection cannot be maintained across different
request/response pairs.
However, session information is maintainable with servlets through various means.
The Java Servlet API includes several Java interfaces and fully defines the link between a
hosting server and servlets.
The Servlet API is defined as an extension to the standard JDK. JDK extensions are packaged
under javax--the root of the Java extension library tree.
The Java Servlet API contains the following packages:
Package javax.servlet
Package javax.servlet.http
Servlets are a powerful addition to the Java environment.
They are fast, safe, reliable, and 100% pure Java. Because servlets plug into an existing server,
they leverage a lot of existing code and technology.
The server handles the network connections, protocol negotiation, class loading, and more; all
of this work does not need to be replicated! And, because servlets are located at the middle tier,
they are positioned to add a lot of value and flexibility to a system.
5.6 Protocol Support
The Servlet API provides a tight link between a server and servlets.
This allows servlets to add new protocol support to a server.
We will see how HTTP support is provided for you in the API packages.
Essentially, any protocol that follows a request response-computing model can be implemented
by a servlet. This could include:
SMTP
POP
FTP
Servlet support is currently available in several web servers, and will probably start appearing
in other types of application servers in the near future.
You will use a web server to host the servlets in this class and only deal with the HTTP
protocol.
Because HTTP is one of the most common protocols, and because HTML can provide such a
rich presentation of information, servlets probably contribute the most to building HTTP based
systems.
Some web servers, such as the Java Web Server (JWS), allow servlet tags to be embedded
directly into HTML files.
When the server encounters such a tag, it calls the servlet while it is sending the HTML file to
the client.
This allows a servlet to insert its contribution directly into the outgoing HTML stream.
As displayed in the above diagram, there are three states of a servlet: new, ready and end. The
servlet is in new state if servlet instance is created. After invoking the init() method, Servlet comes
in the ready state. In the ready state, servlet performs all the tasks. When the web container invokes
the destroy() method, it shifts to the end state.
The web container calls the service method each time when request for the servlet is received.
If servlet is not initialized, it follows the first three steps as described above then calls the service
method.
If servlet is initialized, it calls the service method.
Notice that servlet is initialized only once.
The syntax of the service method of the Servlet interface is given below:
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
The web container calls the destroy method before removing the servlet instance from the
service.
It gives the servlet an opportunity to clean up any resource for example memory, thread etc.
The syntax of the destroy method of the Servlet interface is given below:
public void destroy()
In HTML to servlet communication, when we open the browser window, the browser page is empty.
First, we enter the HTML (static web resource) that resides in the server.
After the HTML page is downloaded from the server to the client side browser, the client will be able to
enter the data in the HTML form.
After submission of the data, request is generated to dynamic web resource.
Hence, we generate request for the server twice in order to get HTML to servlet communication.
So far we have sent request to servlet program from browser window by typing request URL in the
browser window in this process to send data along with request we need to add query string to the
request URL explicitly. But this work can be done only by technical people.
Non technical end users like civil engineer, chemical engineer, kids can't do this work so they need a
graphical user interface to generous request with or without data For that purpose we can use either
Html form page or hyperlink to generous with or without data.
The form page generated request carries form data as request parameters along with request.
In this section, we will learn about HTML to servlet communication by using Hyperlink. For
establishing this type of interaction, we have to pass the URL pattern of the servlet as a value of "href
attribute" of the "action tag".
It is to be noted that when we are using hyperlink, the request is submitted to the servlet using "http get
method".
Hyperlink are favorable for either of inter or intra linking between the pages, but not for
communication between active resources.
In other words, only static data can be passed from HTML to servlet and not the dynamic data.
In second example, the static data UName=King and Pass=Queen will be send to servlet.
Generally the hyperlink generated request is blank request that means it can not carry any data along
with the request.
html files of web application must be placed parallel to WEB-INF folder in deployment directory
structure of web application there is no need of configure then in web.xml file.
Example Application (hyperlink-based HTML to servlet program communication)
• WishSrv servlet program generates the wish message based on the server machine current time.
• .html-based web page are always static pages, whereas servlet and JSP program based web pages can be
static or dynamic pages.
Step 1: Prepare the deployment directory structure of web application.
Step 2: Develop the source code of above servlet program or webApplication
• Place servlet program request URL with URL pattern as the value of href attribute.
ABC.HTML
<!-- Web page having hyper links -->
<a href=http://localhost:2020/WishApp/wurl>GET WISHING
</a>
WishSrv.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import Java.util.*;
public class wishsrv extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException ,
IOException
{
//get the printwriter object
printWriter pw=res.getWriter();
res.setContentType("text/html");
//set the mime type response
Calendar cl=Calendar.getInstance();
//give curent date and time
//get cuurent hour of day
int h=cl.get(Calendar.HOUR_OF_DAY);
if(h<=12)
pw.println("<center><font color='red' size=6> GOOD MORNING </FONT>
</CENTER>")' ;
else if (h>17)
pw.println("<center><font color='red' size=6> GOOD AFTERNOON </FONT>
</CENTER>") ;
else
pw.println(.,"<center><font color='red' size=6> GOOD NIGHT </FONT></CENTER>") ;
pw.println (“<center><font color='red' size=6> <a href=' http://localhost :2020/ Wishapp/home.html'>
HOME</a></FONT></CENTER>");
pw,close() ;
}//end of service
}/ / end of class
web.xml
<web-app>
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>wishSrv</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/wurl</url-pattern>
</servlet-mapping>
</web-app>
-----------------------------UNIT V COMPLETE------------------------------