Web Technology
Web Technology
Web Technology
UNIT II 9
Style Sheets: CSS-Introduction to Cascading Style Sheets-Features-Core Syntax-Style Sheets and HTML
Style Rle Cascading and Inheritance-Text Properties-Box Model Normal Flow Box Layout-Beyond the
Normal Flow-Other Properties-Case Study. Client- Side Programming: The JavaScript Language-History
and Versions Introduction JavaScript in Perspective-Syntax Variables and Data Types-Statements-
Operators- Literals-Functions-Objects-Arrays-Built-in Objects-JavaScript Debuggers.
UNIT III 9
Host Objects : Browsers and the DOM-Introduction to the Document Object Model DOM History and
Levels-Intrinsic Event Handling-Modifying Element Style-The Document Tree-DOM Event Handling-
Accommodating Noncompliant Browsers Properties of window-Case Study. Server-Side Programming:
Java Servlets- Architecture -Overview-A Servelet-Generating Dynamic Content-Life Cycle-Parameter
Data-Sessions-Cookies- URL Rewriting-Other Capabilities-Data Storage Servelets and Concurrency-Case
Study- Related Technologies.
UNIT IV 9
Representing Web Data: XML-Documents and Vocabularies-Versions and Declaration -Namespaces
JavaScript and XML: Ajax-DOM based XML processing Event-oriented Parsing: SAX-Transforming
XML Documents-Selecting XML Data:XPATH-Template based Transformations: XSLT-Displaying
XML Documents in Browsers-Case Study- Related Technologies. Separating Programming and
Presentation: JSP Technology Introduction-JSP and Servlets-Running JSP Applications Basic JSP-
JavaBeans Classes and JSP-Tag Libraries and Files-Support for the Model-View-Controller Paradigm-
Case Study-Related Technologies.
UNIT V 9
Web Services: JAX-RPC-Concepts-Writing a Java Web Service-Writing a Java Web Service Client-
Describing Web Services: WSDL- Representing Data Types: XML Schema-Communicating Object
Data: SOAP Related Technologies-Software Installation-Storing Java Objects as Files-Databases and
Java Servlets.
UNIT I
WEB ESSENTIALS
Pre-requisite discussion:
Introduction:
Web Essentials:
Server:
The software that distributes the information and the machine where the information and software
reside is called the server.
• provides requested service to client
• e.g., Web server sends requested Web page
Client
:
The software that resides on the remote machine, communicates with the server, fetches the
information, processes it, and then displays it on the remote machine is called the client.
Software that delivers Web pages and other documents to browsers using the HTTP protocol
Web Page:
A web page is a document or resource of information that is suitable for the World Wide Web and
can be accessed through a web browser.
Website:
A collection of pages on the World Wide Web that are accessible from the same URL and
typically residing on the same server.
URL:
Uniform Resource Locator, the unique address which identifies a resource on the Internet for
routing purposes.
Client-server paradigm:
The Client-Server paradigm is the most prevalent model for distributed computing protocols. It is
the basis of all distributed computing paradigms at a higher level of abstraction. It is service-oriented, and
employs a request-response protocol.
A server process, running on a server host, provides access to a service. A client process, running
on a client host, accesses the service via the server process.The interaction of the process proceeds
according to a protocol.
The primary idea of a client/server system is that you have a central repository of information—
some kind of data, often in a database—that you want to distribute on demand to some set of people or
machines.
The Internet:
• Medium for communication and interaction in inter connected network.
• Makes information constantly and instantly available to anyone with a connection.
Web Browsers:
• User agent for Web is called a browser:
o Internet Explorer
o Firefox
Web Server:
• Server for Web is called Web server:
o Apache (public domain)
o MS Internet Information Server
Protocol:
Protocols are agreed formats for transmitting data between devices.
The protocol determines:
i. The error checking required
ii. Data compression method used
iii. The way the end of a message is signalled
iv. The way the device indicates that it has received the message
Internet Protocol:
There are many protocols used by the Internet and the WWW:
o TCP/IP
o HTTP
o FTP
o Electronic mail protocols IMAP
o POP
TCP/IP
The Internet uses two main protocols (developed by Vincent Cerf and Robert Kahn)
Transmission control protocol (TCP):Controls disassembly of message into packets at the origin
reassembles at the destination
Internet protocol (IP):Specifies the addressing details for each packet Each packet is labelled with
its origin and destination.
• The hypertext transfer protocol (HTTP) was developed by Tim Berners-Lee in 1991
• HTTP was designed to transfer pages between machines
• The client (or Web browser) makes a request for a given page and the Server is responsible for
finding it and returning it to the client
• The browser connects and requests a page from the server
• The server reads the page from the file system, sends it to the client
and terminates the connection.
The disadvantage of POP: You can only access messages from one PC.
The disadvantage of IMAP :Since email is stored on the email server, there is a need for more and more
expensive (high speed) storage space.
World Wide Web: comprises software (Web server and browser) and data (Web sites).
Internet Protocol (IP) Addresses:
- Every node has a unique numeric address
- Form: 32-bit binary number
- New standard, IPv6, has 128 bits (1998)
- Organizations are assigned groups of IPs for their computers
- Domain names
- Form: host-name. domain-names
- First domain is the smallest (Google)
- Last domain specifies the type of organization (.com)
- Fully qualified domain name - the host name and all of the domain names
- DNS servers - convert fully qualified domain names to IPs
HTTP:
Hypertext Transfer Protocol (HTTP) is the communication protocol used by the Internet to
transfer hypertext documents.
A protocol to transfer hypertext requests and information between servers and browsers
Hypertext is text, displayed on a computer, with references (hyperlinks) to
other text that the reader can immediately follow, usually by a mouse HTTP is behind every request for a
web document or graph, every click of a hypertext link, and every submission of a form.
HTTP specifies how clients request data, and how servers respond to these requests.
The client makes a request for a given page and the server is responsible for finding it and
returning it to the client.
The browser connects and requests a page from the server.
The server reads the page from the file system and sends it to the client and then
terminates the connection
HTTP Transactions
HTTP Message:
HTTP message is the information transaction between the client and server.
1. Requests
a. Client to server
2. Responses
a. Server to client
Field
s · Request line or Response line
· General header
· Request header or Response header
· Entity header
· Entity body
Request Line:
• A request line has three parts, separated by spaces
o a method name
o the local path of the requested resource
o the version of HTTP being used
• A typical request line is:
o GET /path/to/file/index.html HTTP/1.1
• Notes:
o GET is the most common HTTP method; it says "give me this resource". Other
methods include POST and HEAD. Method names are always uppercase
o The path is the part of the URL after the host name, also called the request URI
o The HTTP version always takes the form "HTTP/x.x", uppercase.
Request Header:
.11 Response
Message:
Response Line:
• A request line has three parts, separated by spaces
o the HTTP version,
o a response status code that gives the result of the request, and
o an English reason phrase describing the status code
• Typical status lines are:
o HTTP/1.0 200 OK or
o HTTP/1.0 404 Not Found
• Notes:
o The HTTP version is in the same format as in the request line, "HTTP/x.x".
o The status code is meant to be computer-readable; the reason phrase is meant to be
human-readable, and may vary.
EXAMPLE
HTTP Method:
• HTTP method is supplied in the request line and specifies the operation that the client has
requested.
Some common methods:
• Options
• Get
• Head
• Post
• Put
• Move
• Delete
Two methods that are mostly used are the GET and POST:
o GET for queries that can be safely repeated
o POST for operations that may have side effects (e.g. ordering a book from an on-line store).
• It is used to retrieve information from a specified URI and is assumed to be a safe, repeatable
operation by browsers, caches and other HTTP aware components
• Operations have no side effects and GET requests can be re-issued.
• For example, displaying the balance of a bank account has no effect on the account and can be
safely repeated.
• Most browsers will allow a user to refresh a page that resulted from a GET, without displaying
any kind of warning
• Proxies may automatically retry GET requests if they encounter a temporary network connection
problem.
• GET requests is that they can only supply data in the form of parameters encoded in the URI
(known as a Query String) – [downside]
• Cannot be unused for uploading files or other operations that require large amounts of data to be
sent to the server.
• Used for operations that have side effects and cannot be safely repeated.
• For example, transferring money from one bank account to another has side effects and should
not be repeated without explicit approval by the user.
• If you try to refresh a page in Internet Explorer that resulted from a POST, it displays the
following message to warn you that there may be side effects:
The POST request message has a content body that is normally used to send
parameters and data
• The IIS server returns two status codes in its response for a POST request
o The first is 100 Continue to indicate that it has successfully received the POST request
o The second is 200 OK after the request has been processed.
• Informational (1xx)
• Successful (2xx)
• Redirection (3xx)
o 301: moved permanently
• Client error (4xx)
o 403 : forbidden
o 404: Not found
• Server error (5xx)
o 503: Service unavailable
o 505: HTTP version not supported
HTTP
Features
Web Browsers :
• Mosaic - NCSA (Univ. of Illinois), in early 1993 First to use a GUI, led to Explosion of Web use
Initially for X-Windows, under UNIX, but was ported to other platforms by late 1993
• Browsers are clients - always initiate, servers react (although sometimes servers require
responses)
• Most requests are for existing documents, using Hypertext Transfer Protocol
• (HTTP) But some requests are for program execution, with the output
being returned as a document.
Browser: A web browser is a software application for retrieving, presenting, and
traversing information resources on the World Wide Web.
Web Servers:
- Provide responses to browser requests, either existing documents or dynamically Built documents.
- Browser-server connection is now maintained through more than one request- Response cycle
- All communications between browsers and servers use Hypertext Transfer Protocol
- Web servers run as background processes in the operating system.
- Monitor a communications port on the host, accepting HTTP messages when they appear
All current Web servers came from either
1. The original from CERN
2. The second one, from NCSA
- Web servers have two main directories:
1. Document root (servable documents)
2. Server root (server system software)
- Document root is accessed indirectly by clients
- Its actual location is set by the server Configuration file
- Requests are mapped to the actual location
- Virtual document trees
- Virtual hosts
- Proxy servers
- Web servers now support other Internet protocols
- Apache (open source, fast, reliable)
- IIS
- Maintained through a program with a GUI interface.
Markup Language:
Mark-up Language is used to identify elements of a page so that a browser can render that page on
your computer screen.
Content to be displayed is ―marked up‖ or tagged to tell the browser how to display it.
A markup language is a set of characters or symbols that define a document’s logical structure or how a
document should be printed or displayed.
Hyper Text Mark-up Language, the language used to create documents on the World Wide Web.
· HTML is a collection of styles (indicated by mark-up tags) that define the various elements of a
World Wide Web document.
· HTML document can be read and displayed by many different browsers running on different
types of computers – platform independent!
· HTML defines the structure and layout of the elements on a Web page with a variety of tags.
· Each tag may have a set of attributes that modify the appearance or layout of the visual element
contained by the tag.
· HTML is a plain-text file that can be created using a text editor like Notepad.
· HTML is a programming language that allows you to tell the browser what you want it to display
and how you want it to be displayed, in simple terms, it is a Webpage.
· HTML there are certain markers, like commands, that tell the Browser what to do, these are
called tags. By using tags you can have tables, fonts, colors, pictures, links, and almost anything you can
think up, and experimentation with tags can lead to some pretty cool WebPages.
HTML History:
· The first version of HTML was created using the Standard Generalized Mark up Language
(SGML).
· In the early years of HTML, Web developers were free to define and modify HTML in whatever
ways they thought best.
· Competing browsers introduced some differences in the language. The changes were called
extensions.
· A group of Web developers, programmers, and authors called the World Wide Web
Consortium, or the WC3, created a set of standards or specifications that all browser manufacturers were
to follow.
· The recommendations of the WC3are usually followed since a uniform approach to Web page
creation is beneficial to everyone.
C o m p aris o n of H T M L versions:
HTML 3 HTML 4 HTML 5
<td>left </td>
</tr>
<tr>
<td >footer</td>
</tr>
</table>
</body>
HTML Basics:
HTML Elements
HTML Tags:
• Container Tags
o <Begin formatting>some text</End formatting>
o For example: <B>some bold text</B>
<H1>some heading </H1>
• Empty Element Tags
o For example <HR> <BR>
• Comment Tag
o <!-- Hi, I'm a comment. -->
o Use them document complicated layouts!
• Case insensitive
• Unrecognised tags are simply ignored by browser!!
• Container tags must be nested!!
• As a text document, your HTML in Notepad will contain elements, such as headers, titles, paragraphs,
etc.
• These elements must be denoted in your script, which is done using tags
• HTML tags consist of a left angle bracket (<), a name, and a right angle bracket(>)
• For example: <title>
• Tags must also close. To do so, you incorporate a slash (/). A starting and ending tag would be: <title>
</title>.
Attributes:
Text Styling
• Underline style<U>…</U>
• Align elements with ALIGN attributeright, left or center
• Close nested tags in the reverse order from which they were opened
• Emphasis (italics) style<EM>…</EM>
• Strong (bold) style<STRONG>…</STRONG>
• <B> and <I> tags deprecated Overstep boundary between content and presentation
• Logical Styles:
o <EM>, <STRONG> a add emphasis to text
o <BIG>, <SMALL> a increase or decrease text size
o <SUB>, <SUP> a subscript or superscript
• Physical styles:
o <B>, <I>, <U> a Bold, Italics, and Underline text
o <FONT SIZE=# FACE= ―name‖ COLOR=―colorName or #rgb‖ >
o E.g., <FONT SIZE=+2 FACE = ―arial‖ COLOR = ―darkblue‖>
Relative URL
HTML Link:
To create a link to a resource identifiable by a URL
o href: specify a URL of the target resource
o target: specify where to display the target document
e.g.: <a href="index.htm" target="_blank">Home</a>
Open the document "index.htm" in a new browser window
Can also be used to create an anchor within a document
o name: specify the anchor name
e.g.: <a name="chap1"></a><h2>Chapter 1</h2>
The above anchor can be referred to in a URL as
<a href="http://host/file.html#chap1">Chapter 1</a>
1. Absolute URL
• Absolute URL contains all the information necessary to identify files on the internet (Example:
in postal service, for sending letter to the destination it necessary to have full information like, name,
address, city etc.,)
• Likewise, an absolute URL contains the protocol, hostname, filename, which are all essential to
link the web document.
• Example:
i. http://google.com/index.html
Relative URL
• Relative URL contains the only the folder name and filename or even just the file name.
• Browser does not need protocol address or server name to identify the file in the web.
• Relative URL to refer the documents in relation to the originating document.
This section discusses the A tag which is used to define anchors (places in a document that can be
linked to) and also to create links.
•A
A - (anchor or link)
The A tag lets you define anchors and links. An anchor defines a place in adocument. A link
displays a hypertext link that the user can click to display an anchor or a document.
A as anchor
An anchor identifies a place in an HTML document. To indicate that an <A> tag is being used as
an anchor, specify the NAME attribute.
Note that you can also use the ID attribute of any tag to identify that tag as an anchor, as discussed
in UNIVERSAL Attributes.
Do not nest an anchor within another A tag.
Synta
x <A
NAME="anchorName"
>.
..
</A>
Example
<A NAME=section2>
<H2>A Cold Autumn Day</H2></A>
If this anchor is in a file called "nowhere.htm," you could define a link that jumps to the anchor
as follows:
<P>Jump to the second section <A
HREF="nowhere.htm#section2"> A Cold Autumn Day</A> in
the mystery "A man from Nowhere."
A as link
• A hypertext link is a piece of content that the user can click to invoke an action.
• The most common actions are scrolling to a different place in the current document and
opening a new document.
• A hypertext link can contain text and/or graphics.
• To define a hypertext link, use the <A> tag with an HREF attribute to indicate the start of the
hypertext link, and use the </A> tag to indicate the end of the link.
• When the user clicks any content between the <A HREF> and </A> tags, the link is activated.
• The value of the HREF attribute must be a URL.
• If you want the link to open a new document, the value of HREF should be the URL for the
destination document.
• If you want to scroll the current document to a particular place, the value of HREF should be
the name of the anchor to which to scroll, preceded by the # sign.
• If you want to open another document at an anchor, give the URL for the document, followed
by #, followed by the name of the anchor.
• If you want the destination document or anchor to open in a separate browser window, supply
the name of the window as the value of the TARGET attribute.
• If the named window does not already exist, a new window opens.
• The link can also do actions other than opening and scrolling documents. It can send mail
messages, point to files located on FTP servers, run any arbitrary JavaScript code, open local files, point to
a gopher server, or read news groups.
• To do any of these actions, you specify an appropriate kind of URL, such as a mailto URL to send
a mail message or a news URL to read a news group.
• Most browsers display hypertext links in a color different from that of the rest of the document so
that users can easily identify them.
• You can also define actions that occur when the mouse cursor enters or leaves the region
containing the link by specifying onMouseOver and onMouseOut event handlers for the link.
• Additionally, you can specify an onClick event handler that determines the action to occur when
the user clicks a link.
• A link that has not been clicked is called an unvisited link.
• A link that has been clicked is known as a visited or followed link.
• A link that is in the process of being clicked is an active link.
Syntax
<A
HREF="location"
ONCLICK="clickJScode"
ONMOUSEOUT="outJScode"
ONMOUSEOVER="overJScode"
TARGET="windowName"
>
...
</A>
HREF="location" specifies a destination URL for the link. The most common value here is a
document name or an anchor. To specify a document to open, provide the URL for the document, either as
an absolute or relative URL.
To scroll the current document to an anchor, give the name of the anchor preceded by the pound
(#) sign. For example:
HREF="#anchor1"
To open a different document at an anchor, give the URL for the document, followed by the # sign
followed by the name of the anchor. For example:
HREF="products/doc1.html"
The HREF attribute can also be a URL that sends a message, points to files located on an FTP
server, runs arbitrary JavaScript code, opens local files, points to a gopher server, or reads news groups.
ONCLICK="clickJScode" specifies JavaScript code to execute when a user clicks the link. If you supply
a value for the ONCLICK attribute, the specified action overrides the default link
behavior.
ONMOUSEOUT="outJScode" specifies JavaScript code to execute when a user moves the mouse
cursor out of the link or anchor.
ONMOUSEOVER="overJScode" specifies JavaScript code to execute when a user moves the mouse
pointer over the image or link text.
TARGET="windowName" specifies a window in which to show the destination document (if the link's
action is to scroll or open a document). If the named window is not already open, a new window with that
name opens.
Special target values are:
parent opens the destination document in the parent window of the one displaying the current
document.
self opens the destination document in the same window as the one in which the link was clicked.
top opens the destination document in the full body of the current window. This value can be used
to ensure that the destination document takes over the full window even if the original document was
displayed in a frame.
Example
<P>You can find all the latest news from Chennai Kavigal at
<A HREF="http://www.chennaikavigal.com/index.html">Chennai Kavigal's
Home Page</A>.
HTML List:
Lists can add a lot to a WebPage, there are different types of lists and different
types of bullets or numbers that can be used.
You can have an ordered list (a, b, c, etc.) unordered lists (with bullets) or you
can have definition lists.
This section describes the tags for displaying lists:
DIR, DL, DT, DD, MENU, OL, UL, LI
DIR - (directory list)
The DIR tag is intended to display a list of short items such as in a directory listing. In
practice, the DIR tag usually does the same thing as the UL (unordered list) tag.
To mark the individual items within the list, use the LI tag. A single list item can contain
additional paragraphs, marked with the P tag.
This tag is being deprecated; that is, it has become obsolete.
Syntax
<DIR>
...
</DIR>
Example
DL - (definition list)
The DL tag encloses a definition list. A definition list contains terms, which are defined with the
DT tag, and definitions, which are defined with the DD tag. By default, Nadodi aligns
terms on the left and indents each definition on a new line. However, you can use the COMPACT attribute
to display a definition on the same line as the preceding term, if it fits on
one line.
The intent of a definition list is to display lists of terms and their corresponding definitions, such as
in a glossary.
Syntax
<DL COMPACT>
...
</DL>
COMPACT compacts the definition list by placing the term defined by the DT tag on the same line as the
definition defined by the DD tag, provided the term is short enough.
DT - (definition term)
The DT tag specifies a term in a definition list. The DT tag must be used in a DL tag. Usually a DT
tag is followed by a DD tag that describes the term in the DT tag.
The DT tag does not require a closing tag.
Syntax <DT>
Used Within <DL>
DD – (Definition description)
The DD tag displays a definition description in a definition list. The DD tag must be used
within a DL tag and usually follows immediately after a DT tag that indicates the term being defined. The
DD tag does not require a closing tag.
See DL for more details and an example.
Syntax <DD>
Used Within <DL>
1. Unordered List:
• In an unordered list each item has the same leading symbol.
• The item in the list will be rendered in the same order that they are entered.
• <ul> tag is used to unordered the list.
• <li> tag is used to list the items.
Synta
x
1. <UL TYPE="CIRCLE"|"DISC"|"SQUARE">
TYPE defines the type of bullet used for each list item. The value can be one of the following:
CIRCLE specifies a hollow bullet.
DISC specifies a solid round bullet (Nadodi's default).
SQUARE specifies a square bullet.
Example
<ul type=‖disc‖>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ul type="square">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ul type="circle">
<li>Item 1</li>
<li>Item 2</li>
</ul>
2. Ordered List:
• In an ordered list, each item has a sequential leading symbol.
• The browser assigns this sequence automatically.
• <ol> tag is used to ordered the list.
• <li> tag is used to list the item.
Syntax
<OL
START="value"
TYPE="A"|"a"|"I"|"i"|"
1"
>
...
</OL>
START="value" indicates the starting number for the list. The number must be a positive integer.
TYPE defines the type of numbering sequence used for each list
item. The value can be one of the following:
A specifies a sequence of uppercase letters
a specifies a sequence of lowercase letters
I specifies a sequence of uppercase Roman numerals
i specifies a sequence of lowercase Roman numeral
1 specifies a sequence of numbers.
Example
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
<ol type="A" start="5">
<li>Item 1</li>
<li>Item 2</li>
</ol>
<ol type="i" start="10">
<li>Item 1</li>
<li>Item 2</li>
</ol>
3. Definition List
• A definition list is a sequence of terms and description of these terms.
• <dl> tag is used to implement definition list.
• <dt> tag is used for defining the item.
• <dd> tag is used for defining the description.
LI - (list item)
The LI tag indicates an itemized element, which is usually preceded by a bullet, a number, or a
letter. The LI tag is used inside list elements such as OL (ordered list) and UL (unordered list).
A single itemized element can contain other tags such as the P tag.
The LI tag does not require a closing tag.
Syntax
<LI
TYPE="DISC"|"CIRCLE"|"SQUARE"|"A"|"a"|"I"|"i"|"1"
VALUE="number"
>
TYPE specifies the type of symbol or numbering sequence to use before each item.
· DISC specifies a solid bullet.
· CIRCLE specifies a hollow bullet.
· SQUARE specifies a square bullet.
· A specifies a sequence of uppercase letters.
· a specifies a sequence of lowercase letters.
· I specifies a sequence of uppercase Roman numerals.
· i specifies a sequence of lowercase Roman numeral.
· 1 specifies a sequence of numbers.
The values DISC, CIRCLE, and SQUARE can be used in unordered lists, while the values A, a, I, i, and 1
can be used in ordered lists that have a numerical sequence.
VALUE="number" indicates the starting number for an item in an ordered list. This attribute is valid
only in an ordered list. See OL for information on the types of numbering available.
HTML Table:
• Tables in HTML are easy to program if you know what you are trying to do.
• Tables look like the charts present on many of these slides.
• Tables in browsers by default have no borders, if you want to see the edges of your table, you
have to place a border command inside the table tag.
• You can also use tables to format pages.
• Inside tables, the text is always the default of the browser (black and small), if you want to
change this font, you must add a <font color=―color‖ and/or size=―x‖> inside each cell to make the
change.
· TABLE
· CAPTION
· TR
· TD
· TH
TABLE - (table): The TABLE tag defines a table. Inside the TABLE tag, use the TR tag to define rows in
the table, use the TH tag to define row or column headings, and use the TD tag to define table cells.
The TABLE tag can also contain a CAPTION tag, which specifies the caption
for the table.
You can specify the width of the border surrounding the table and the default
background color of the table. (Individual rows and cells in the table can have their own background
color.) You can use the CELLSPACING attribute to specify the distance between cells in the table and the
CELLPADDING attribute to specify the distance between the border and content of every cell. If you
specify the width and height of the table, the browser will do its best to make the table fit the specified
dimensions, but in some cases this may not be possible. For example, if the table contains cells that
contain non-wrapping long lines, the table may not fit in a specified width.
Synta
x <TABLE
ALIGN="LEFT|
RIGHT"
BGCOLOR="color"
BORDER="value"
CELLPADDING="val
ue"
CELLSPACING="valu
e"
HEIGHT="height"
WIDTH="width"
COLS="numOfCols"
HSPACE="horizMarg
in"
VSPACE="vertMargi
n"
>
...
</TABLE>
BGCOLOR="color"sets the color of the background for the table. This color can be overridden by a
BGCOLOR tag in the TH, TR, or TD tags.
BORDER="value" indicates the thickness, in pixels, of the border to draw around the table. Give the
value as an integer. A value of 0 means the table has no border. You can also supply the BORDER attribute
without specifying a value for it to indicate that the table has a border of the default thickness.
CELLPADDING="value" determines the amount of space, in pixels, between the border of a cell and
the contents of the cell. The default is 1.
CELLSPACING="value"determines the amount of space, in pixels, between individual cells in a table.
The default is 2.
HEIGHT="height" specifies the height of the table. The default is the optimal height determined by the
contents of each cell. The height value can be a number of pixels, given as an integer, or a percentage of
the height of the page or parent element, given as an integer followed by the percent sign. The table is
scaled to fit the specified height and width.
WIDTH="width" defines the width of the table. The default is the optimal width determined by
the contents of each cell.
The width value can be a number of pixels, given as an integer, or a percentage of the width of the
page or parent element, given as an integer followed by the percent sign. The table is scaled to fit the
specified height and width.
COLS="numOfCols" indicates how many virtual columns of equal width fit in the width of the
window. Each actual column in the table occupies a virtual column. You would typically set the COLS
attribute to be equal to the number of columns in the table to indicate that all the columns in the table have
the same width.
If the WIDTH attribute is supplied, the COLS attribute indicates how many virtual columns fit in
the specified width. If the WIDTH attribute is not supplied, the COLS attribute indicates how many virtual
columns fit in the current window or frame. Each column in the table occupies one of the virtual columns.
Suppose that the WIDTH attribute is "80%" and the COLS attribute is 4.
In this case, each virtual column takes up 20% of the width of the window. Each actual column in
the table occupies a virtual column, so it occupies 20% of the width of the window, so long as the table has
from 1 to 4 columns inclusive. Note, however, that if the minimum width needed to display the contents of
an actual column is greater than the width of a virtual column, then the width of the column is expanded to
fit its contents.
If the table has more actual columns than the COLS value, then the columns in excess of the COLS
value are displayed in the minimum width required to fit their contents, and the other columns divide the
remaining space equally between them.
For example, suppose the table has 4 columns, the WIDTH attribute is "80%", and the COLS value
is 3. What happens here is that the table takes up 80% of the width of the window. The fourth column uses
the minimum width necessary to display the contents of the column. The other 3 columns divide the
remaining width of the table equally between them.
HSPACE="horizMargin" specifies the distance between the left and right edges of the table and any
surrounding content.
VSPACE="vertMargin" specifies the distance between the top and bottom edges of the table and any
surrounding content.
TR - (table row) The TR tag specifies a table row. Use the TR tag inside a TABLE tag. The TR tag can
contain TH tags, which indicate table headings, and TD tags, which indicate table cells.
Syntax
<TR ALIGN="CENTER|LEFT|
RIGHT"
VALIGN="BASELINE|BOTTOM|MIDDLE|TOP"
BGCOLOR="color"
>
...
</TR>
ALIGN specifies the horizontal placement of the table:
· CENTER centers the table .
· LEFT aligns the table to the left (the default).
· RIGHT aligns the table to the right.
VALIGN specifies the vertical placement of the content in the cell:
· BASELINE aligns the content with the cell's baseline.
· BOTTOM aligns the content with the cell's bottom.
· MIDDLE centers the content within the cell (the default).
· TOP aligns the content with the cell's top.
BGCOLOR="color" sets the default color of the background of the table row. Table cells defined with
the TD tag inside the row can set their own background color.
Used within TABLE
Example See example 1. Simple Table.
TD - (table data)
The TD tag specifies text in a cell in a table. Use the TD tag inside a TR tag
inside a TABLE tag.
You can set the background color of a cell by specifying its BGCOLOR attribute. For each cell,
you can use the COLSPAN and ROWSPAN attributes to specify how many columns and rows the
cell spans.
To specify the distance between cells, set the CELLSPACING attribute in the TABLE tag. To
specify the distance between the borders of each cell and its contents, set the CELLPADDING attribute in
the TABLE tag. All cells in a table have the same padding and spacing.
If a cell is empty, that is, the <TD> tag is immediately followed by the </TD> tag, the space
occupied by the cell in the table is completely empty. That is, the cell has no content, no background color,
and no border. However, suppose you have a four column table, but you have no data for the second
column in one of the rows. You should still provide the second TD tag for that row, because if you leave it
out the table will close the gap and move the third cell into the second column. The row will end up having
three columns only, and it will not be aligned with the rest of the table
If you want an empty cell to look like other cells in the table, you can give it a period or a dash to
indicate that the data is unknown, for example, <TD> -
</TD>.
Syntax
<TD ALIGN="CENTER|LEFT|
RIGHT"
VALIGN="BASELINE|BOTTOM|MIDDLE|TOP"
BGCOLOR="color"
COLSPAN="value"
ROWSPAN="value"
HEIGHT="pixelHeight"
WIDTH="pixelWidth"
NOWRAP="value"
>
...
</TD>
ALIGN specifies the horizontal placement of the contents of the table cell:
· CENTER centers the content within the cell.
· LEFT aligns the content with the cell's left edge (the default).
· RIGHT aligns the content with the cell's right edge.
VALIGN specifies the vertical placement of the contents of the cell:
· BASELINE aligns the content with the cell's baseline.
· BOTTOM aligns the content with the cell's bottom.
· MIDDLE centers the content within the cell (the default).
· TOP aligns the content with the cell's top.
BGCOLOR="color" sets the color of the background of the table cell.
COLSPAN="value" indicates the number of columns the cell spans. Give the number as an integer.
ROWSPAN="value" indicates the number of rows the cell spans. Give the value as an integer.
HEIGHT="pixelHeight" specifies the suggested height of the table cell, in pixels.
WIDTH="pixelWidth" specifies the suggested width of the table cell, in pixels.
NOWRAP specifies that the lines within a cell cannot be broken (that is, they do not wrap onto the next
line).
Used Within TABLE and TR
Example See example 1. Simple Table.
TH - (table heading) The TH tag specifies a table cell whose contents are usually displayed in a
bolder font than those of regular table cells. The intent of the TH tag is that you use it for column or row
headings.
Syntax
<TH ALIGN="CENTER|LEFT|
RIGHT"
VALIGN="BASELINE|BOTTOM|MIDDLE|TOP"
BGCOLOR="color"
COLSPAN="value"
ROWSPAN="value"
HEIGHT="pixelHeight"
WIDTH="pixelWidth"
NOWRAP
>
...
</TH>
ALIGN specifies the horizontal placement of the heading in the table cell:
· CENTER centers the content within the cell.
· LEFT aligns the content with the cell's left edge (the default).
· RIGHT aligns the content with the cell's right edge.
VALIGN specifies the vertical placement of the contents of the cell:
· BASELINE aligns the content with the cell's baseline.
· BOTTOM aligns the content with the cell's bottom.
· MIDDLE centers the content within the cell (the default).
· TOP aligns the content with the cell's top.
BGCOLOR="color" sets the color of the background of the table heading. This color can be overridden
by a BGCOLOR tag in the TD tags within the TH tag.
COLSPAN="value" indicates the number of columns the cell spans.
ROWSPAN="value" indicates the number of rows the cell spans.
HEIGHT="pixelHeight" specifies the suggested height of the table cell, in pixels.
WIDTH="pixelWidth"specifies the suggested width of the table cell, in pixels.
NOWRAP specifies that the lines within a cell cannot be broken; that is, they do not wrap
onto the next line.
Table's Attributes
border (example)
This specifies the width in pixels of the border around the table
This is in addition to the border around each cell (the "cellspacing").
The default is zero
cellspacing (example)
This gives the space in pixels between adjacent cells.
The default is usually about 3
cellpadding (example)
Specifies the space between the cell walls and contents
The default is usually about 1
widt
h This specifies the width of the
table In pixels (<table
width="250">), or
As a percentage of the current browser window width
(<table width="75%">)
rules (example) Specifies the horizontal/vertical divider
lines. Must be used in conjunction with the "border"
attribute!
frame (example) Specifies which outer borders are drawn.All four are drawn if this attribute is omitted.
HTML Frames:
Frames and
Framesets
This section discusses the tags for creating frames and frame sets. A frame is region of a
window that acts as a window itself. The main window can contain multiple frames, so that different
regions of the window display different contents. A frame set is a set of frames.
· FRAME
· FRAMESET
· NOFRAMES
FRAME - (window region)
The FRAME tag creates a frame, which is an individual, independently scrollable region of a web
browser. You can think of it as a window within a window. The FRAME tag must be used within a
FRAMESET tag.
The FRAMESET tag contains a set of FRAME tags, which each define a frame in the main
window.
Each frame has a distinct URL that determines the content displayed by the frame.
You can specify whether or not a frame has a border, whether or not it has margins, whether or not
the user can resize it dynamically, and whether or not it is scrollable.
Syntax
<FRAME
BORDERCOLOR="color"
FRAMEBORDER="YES"|"NO"
MARGINHEIGHT="marginHeight"
MARGINWIDTH="marginWidth"
NAME="frameName"
NORESIZE
SCROLLING="YES"|"NO"|"AUTO"
SRC="URL"
>
The URL tag is required.
BORDERCOLOR="color" specifies the color of the frame's borders. Because frames share borders,
Navigator must resolve any border color conflicts.
FRAMEBORDER determines whether or not the frame has visible borders.
· YES results in an outline-3D border.
· NO suppresses the 3D border.
When the FRAMEBORDER attribute appears in a FRAMESET tag, it sets a default
FRAMEBORDER value for all frames in the frameset. When the FRAMEBORDER attribute appears in
the FRAME tag, it applies only to that particular frame, overriding any FRAMEBORDER attribute
established by an outer FRAMESET tag. A border shared between frames is plain only if all adjacent
frames have the FRAMEBORDER attribute set to NO.
When neither a FRAME nor a FRAMESET tag governing that FRAME has set
the FRAMEBORDER attribute, the default setting is YES.
MARGINHEIGHT="marginHeight" specifies a margin, in pixels, between the top and bottom edges of
the frame and the frame contents.
MARGINWIDTH="marginWidth" specifies a margin, in pixels, between the left and right edges of the
frame and the frame contents.
NAME="frameName" specifies the name of the frame. The value of the NAME attribute must begin
with an alphanumeric character.
NORESIZE specifies that users cannot resize the frame. If a frame adjacent to an edge is not resizable, the
entire edge is not resizable, and consequently other frames adjacent to that edge are not resizable.
COLS="columnWidthList" specifies a comma-separated list of values giving the width of each frame in
the frameset. If one of the values is missing, the browser sizes the corresponding frame to fit the space
available.
The browser may approximate some values to make the total width of the columns equal to the
width of the window.
The value of each item in the columnWidthList can be one of the following:
· Width of a frame in pixels.
· Width of a frame as a percentage of its parent frame or window.
· An asterisk (*), which means "as much space as possible," which is the space left over
after space has been allocated to all columns that specify their width as pixel value or a percentage
value . The total available left-over space is divided equally between all columns that use an
asterisk.
ROWS="rowHeightList" specifies a comma-separated list of values giving the height of each frame in
the frameset. If one of the values is missing, the corresponding frame is sized to fit the space available.
The browser may approximate some values to make the total height of the rows equal to the height of the
window. Each item in rowHeightList can be one of the following:
BORDER="pixWidth" specifies the thickness of frame borders for all frames in an outermost frameset.
A setting of 0 causes all frames in the frameset to have no border between them. A setting of 3 causes a
border of 3 pixels. If no BORDER tag is present,the default is 5 pixels. The BORDER tag can be used
only on an outermost FRAMESET tag.
BORDERCOLOR="color" specifies the color of a frame's borders. Because frame borders are shared,
Navigator must resolve any border color conflicts.
1. Any BORDERCOLOR attribute appearing in the outermost FRAMESET has the lowest priority.
2. This attribute is overridden by any attribute used in a nested FRAMESET tag.
3. Finally, any BORDERCOLOR attribute in the current FRAME tag overrides all previous
FRAMESET tag settings. If there is a conflict for two colors of equal priority both set on the same edge,
the behavior is undefined.
FRAMEBORDER determines how frame borders are displayed.
· YES results in an outline-3D border.
· NO suppresses the 3D border.
When the FRAMEBORDER attribute appears in the FRAMESET tag, it sets a default
FRAMEBORDER value for all frames in that frameset. When the FRAMEBORDER attribute appears in a
FRAME tag, it applies only to that particular frame, overriding any FRAMEBORDER attribute specified
by an outer FRAMESET tag. A border shared between frames is plain only if all adjacent frames have the
FRAMEBORDER attribute set to NO. When neither a FRAME nor a FRAMESET tag governing that
FRAME has set the FRAMEBORDER attribute, the default setting is YES.
ONBLUR="JScode" specifies JavaScript code to execute when the window containing the frameset loses
focus.
ONFOCUS="JScode" specifies JavaScript code to execute when the window containing the frameset
gets focus.
ONLOAD="JScode" specifies JavaScript code to execute when the frameset is loaded into the
frame.
ONUNLOAD="JScode" specifies JavaScript code to execute when the frameset is unloaded (exited).
The two frames appear as columns because COLS is specified within the FRAMESET tag. The left frame
uses 30% of the available space, and the right frame uses the remaining 70% of the space. By default, the
frames in this example have scrollbars and are resizable, because no values are specified for the
SCROLLING and NORESIZE attributes.
HTML Forms:
• List of
component
Text
Text Area
Label
Button
Check box
Radio button
Menus
1. Tex
t • Text component is used to insert a text in web page.
• <Input> tag is used to insert a text component in document.
• General form
<input type=‖text‖ size=25 value= ― ―>
2. Text Area
• Text Area component is used to feed multiple line of text.
• Attribute in text area component.
• Row: Row attribute used to denote the total number of rows in the text area.
• Column: Column attribute is used to denote the number of column in the text area.
• Name: Name attribute is used to denote the name of the text area.
• Wrap: Wrap attribute is used to wrap the text inside the text area.
• <text area> tag is used to insert the text area in the web document.
• General form:
o <text area cols=‖value‖ rows=‖values‖ >----</text area>
• Example:
o <text area cols=‖50‖ rows=‖40‖ name=‖name‖>---</text area>
3. Label
• Label tag is used to create text box to fill the text.
• This tag has starting tag (<label>) and ending tag (</label>).
• Example
o<label> Name <input type=text size=40>--</label>
4. Check box
• Check box component is used to place the checkbox in the web document.
• General form:
o<input type=checkbox> ----- </input>
Name/Value Pairs
When a form is submitted, the data contained in the form is sent to the invoked CGI program as a
series of name/value pairs. The name portion of each pair is the name of an interface element as specified
by its NAME attribute. In most cases the value portion is the value displayed by the element, for example,
the text displayed in a text field.
Nesting Forms
A document can have multiple forms, but forms cannot be nested -- you cannot have a form within
a form. If your document uses positioned HTML content, each form must be completely contained within
one positioned block.
Syntax
<FORM
ACTION="serverURL"
ENCTYPE="encodingType"
METHOD="GET"|"POST"
NAME="formName"
ONRESET="JScode"
ONSUBMIT="JScode"
TARGET="windowName"
>
...
</FORM>
The ACTION attribute is required if any action is to occur when the user presses a "Submit" button in the
form.
ACTION="serverURL" specifies the URL of the program to be invoked when the form is submitted.
The action can also be a mailto: URL if the form results are to be mailed to someone.
ENCTYPE="encodingType" specifies the MIME encoding of the data sent:
"application/x-www-form-urlencoded" (the default), is usually used if the METHOD attribute has
the value POST.
"multipart/form-data" is used when the form contains a file upload element (INPUT
TYPE="FILE").
METHOD specifies how information is sent to program invoked by submitting the form.
GET (the default) appends the input information to the URL which on most receiving systems
becomes the value of the environment variable QUERY_STRING.
POST sends the input information in a data body that is available on stdin with the data length set
in the environment variable CONTENT_LENGTH.
NAME="formName" specifies the name of the form. The name is not displayed on the form.
JavaScript can use the NAME attribute to differentiate different forms if there are multiple forms on a
page.
ONRESET="JScode" specifies JavaScript code that executes when a user resets the form by using a
RESET button.
ONSUBMIT="JScode" specifies JavaScript code that executes when a user submits the form by clicking
a "Submit" button.You can use the ONSUBMIT attribute to prevent a form from being submitted; to do
so, put a return statement that returns false in the JavaScript code. Any other returned value lets the form
submit. If you omit the return statement, the form is submitted.
TARGET="windowName" specifies the window that displays the data returned by the invoked program.
Example
The following example creates a form called LoginForm that contains text fields for user name and
password, a submit button, and a cancel button.
<FORM NAME="LoginForm" METHOD=POST ACTION="urltoInvoke">
<P>User name:
<INPUT TYPE="text" NAME="userName" SIZE="10">
<P>Password:
<INPUT TYPE="password" NAME="password" SIZE="12">
<P><INPUT TYPE="submit" VALUE="Log in">
<INPUT TYPE="button" VALUE="Cancel" onClick="window.close()">
</FORM>
INPUT TYPE="BUTTON"
A button apears in the form. You must specify JavaScript code as the value of the ONCLICK
attribute to determine what happens when the user clicks the
button.
Synta
x <INPUT TYPE="BUTTON"
NAME="buttonNa
me"
VALUE="buttonTe
xt"
ONCLICK="JScod
e"
>
NAME="buttonName" specifies the name of the button. The name does not appear in the form.
VALUE="buttonText" specifies the text to be displayed in the button.
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks the button.
Example
<FORM METHOD=POST ACTION="/cgi-bin/example.cgi">
<INPUT TYPE="button" VALUE="Close
Window" onClick="window.close();">
</FORM>
INPUT TYPE="CHECKBOX" A checkbox is a toggle that the user can select (switch on) or deselect
(switch off.)
Syntax
<INPUT
TYPE="CHECKBOX"
CHECKED
NAME="name"
ONCLICK="JSco
de"
VALUE="checkboxValue"
>
CHECKED indicates that the checkbox is displayed with a tick mark to indicate that
it is selected.
NAME="name" specifies the name of the input element. This value is the name portion of the
name/value pair for this element that is sent to the server when the form is submitted. The name is not
displayed on the form.
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks the checkbox.
VALUE="checkboxValue" specifies the value to be returned to the server if the checkbox is selected
when the form is submitted. The default value is ON, but you can specify a different value if you want.
When the form is submitted, only the name/value pairs for selected checkboxes are sent to the invoked
CGI program.
Example
<P>Specify your music preferences (check all that apply):</P>
<BR><INPUT TYPE="checkbox" NAME="musicpref_rnb"
CHECKED> R&B
<BR><INPUT TYPE="checkbox" NAME="musicpref_jazz"
CHECKED> Jazz
<BR><INPUT TYPE="checkbox" NAME="musicpref_blues"
CHECKED> Blues
<BR><INPUT TYPE="checkbox" NAME="musicpref_newage" CHECKED>
New Age
INPUT TYPE="FILE" This places an element on an HTML form that lets the user supply a file as input.
When the form is submitted, the content of the specified file is sent to the server as the value portion of the
name/value pair for this input element.
If a form contains a file input element, the value of the ENCTYPE attribute of the FORM tag
should be "multipart/form-data".
Syntax
<INPUT TYPE="FILE"
NAME="name"
VALUE="filename"
>
NAME=name specifies the name of the input element. This value is used as the name portion of the
name/value pair for this element that is sent to the server when the form is submitted. The name is not
displayed on the form.
VALUE=filename specifies the initial value of the input element.
Example
<FORM ENCTYPE="multipart/form-data"
ACTION="/cgi-bin/example.cgi" METHOD="POST">
<P>File name:
<INPUT TYPE="file">
</FORM>
INPUT TYPE="HIDDEN"
A hidden input element is an invisible element whose main purpose is to contain data that the user
does not enter. This data gets sent to the invoked CGI program when the form is submitted.
This tag provides a mechanism for delivering a value to the CGI program without the user having
entered it, but note that it is not very hidden because the user can discover it by viewing the document
source.
Syntax
<INPUT TYPE="HIDDEN"
NAME="name"
VALUE="value"
>
NAME="name" specifies the name of the input element. This value is the name portion of the
name/value pair sent to the invoked CGI program when the form is submitted. The name is not displayed
on the form.
VALUE="value" specifies the initial value of the input element.
Example
This example creates a form with a hidden element, DefaultPass, that stores the initial value of the
password field.
<FORM NAME="LoginForm" METHOD=POST ACTION="/cgibin/
example.cgi">
<P>Password:
<INPUT TYPE="password" NAME="password" SIZE="12"
VALUE="treasure">
<INPUT TYPE="hidden" NAME="DefaultPass" VALUE="treasure">
</FORM>
INPUT TYPE="IMAGE"
This places an image, serving as a custom button, on an HTML form. When a user clicks the
image, the form is submitted to the server.
Syntax
<INPUT TYPE="IMAGE"
ALIGN="LEFT"|"RIGHT"|"TOP"|"ABSMIDDLE"|"ABSBOTTOM"|
"TEXTTOP"|"MIDDLE"|"BASELINE"|"BOTTOM"
NAME="name"
SRC="location"
>
ALIGN specifies the alignment of the image in relation to the surrounding text. If you do not specify a
value for ALIGN, Navigator uses BOTTOM as the default. The possible values are LEFT, RIGHT, TOP,
ABSMIDDLE, ABSBOTTOM, TEXTTOP, MIDDLE, BASELINE, and BOTTOM. See the section
"IMG" for a description of the values.
NAME=name specifies the name of the input element. This value is used as the name portion
of the name/value pair for this element that is sent to the invoked CGI program when the form is
submitted. The name is not displayed on the form.When Navigator sends the offsets of the image to the
server, it sends them as name.x and name.y.
SRC="location" specifies the URL of the image to be displayed in the document.
Example
<CENTER><INPUT TYPE="image" SRC="signnow.gif"></CENTER>
INPUT TYPE="PASSWORD" A password element is a text input field in which each character typed is
displayed as a character such as * or a black dot to conceal the actual value.
Syntax
<INPUT TYPE="PASSWORD"
MAXLENGTH="maxChar"
NAME="name"
ONSELECT="JScode"
SIZE="charLength"
VALUE="textValue"
>
MAXLENGTH="maxChar" specifies the maximum number of characters a password box can accept.
NAME="name" specifies the name of the input element. This value is used as the name portion
of thename/value pair for this element that is sent to the server when the form
is submitted. The name is not displayed on the form.
ONSELECT="JScode” specifies JavaScript code to execute when a user selects some of the text in the
text element.
SIZE="charLength" specifies the length of the input field, in characters. The value should be an integer.
VALUE="textValue"specifies the initial value of the password, if any.
Example
<P>Password:
<INPUT TYPE="password" NAME="password" VALUE="" SIZE="25">
INPUT TYPE="RADIO" A radio element is a radio button. A set of radio buttons consists of multiple
radio buttons that all have the same NAME attribute. Only one radio button in the set can be selected at
one time. When the user selects a button in the set, all other buttons in the set are deselected. If one radio
button in a set has the CHECKED attribute, that one is selected when the set is first laid out on the
window.
Syntax
<INPUT TYPE="RADIO"
CHECKED
NAME="name"
ONCLICK="JScode"
VALUE="buttonValue"
>
CHECKED indicates that the radio button is selected.
NAME="name" specifies the name of the input element. This value is used as the name portion
of the name/value pair for this element that is sent to the invoked CGI program when the form is
submitted. The name is not displayed on the form. All radio buttons that have the same name constitute a
radio group; only one radio button of a group can be set at one time.
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks the radio button.
VALUE="value” specifies the value that is returned to the server when the radio button is selected and
the form is submitted. Only name/value pairs for radio buttons that are selected are sent to the invoked
CGI program. The value defaults to ON.
Example
The following example creates a radio button group.
<P>Category:
<BR><INPUT TYPE="radio" NAME="category" VALUE="liv" CHECKED>
Living
<BR><INPUT TYPE="radio" NAME="category" VALUE="din"> Dining
<BR><INPUT TYPE="radio" NAME="category" VALUE="bed"> Bedroom
INPUT TYPE="RESET" When a user presses a reset button, all elements in the form are reset to their
default values
Syntax
<INPUT TYPE="RESET"
NAME="name"
ONCLICK="JScode"
VALUE="label"
>
NAME="name"specifies the name of the input element.
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks the button.
VALUE="label" specifies the text to display on the face of the reset button.
Example
This example displays a text element with the default value CA and a reset button labelled Clear
Form. If the user types a state abbreviation in the text element and then clicks the Clear Form button, the
original value of CA is restored.
<FORM>
<P>State: <INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2">
<P><INPUT TYPE="reset" VALUE="Clear Form">
</FORM>
INPUT TYPE="SUBMIT" When a user clicks a submit button, the form is submitted, which means that
the ACTION specified for the form is invoked.
Syntax
<INPUT TYPE="SUBMIT"
NAME="name"
VALUE="label">
NAME="name" specifies the name of the input element. The name is not displayed on the form.
VALUE="label" specifies the text to display on the face of the submit button.
Example
<INPUT TYPE="submit" NAME="SubmitButton" VALUE="Done">
INPUT TYPE="TEXT" A text element is a single line text input field in which the user can enter text.
Syntax
<INPUT TYPE="TEXT"
MAXLENGTH="maxChars"
NAME="name"
ONBLUR="Scode"
ONCHANGE="JScode"
ONFOCUS="Scode"
ONSELECT="JScode"
SIZE="lengthChars"
VALUE="text"
>
MAXLENGTH="maxChars" specifies the maximum number of characters a text box can accept.
NAME="name" specifies the name of the input element. This value is used as the name portion
of the name/value pair for this element that is sent to the invoked CGI program when the form is
submitted. The name is not displayed on the form.
ONBLUR="JScode" specifies JavaScript code to execute when the text element loses keyboard
focus.
ONCHANGE="JScode" specifies JavaScript code to execute when the text element loses focus and its
value has been modified.
ONFOCUS="JScode" specifies JavaScript code to execute when a user clicks the text element. See the
JavaScript Guide forSee the JavaScript Guide for more information.
ONSELECT="JScode" specifies JavaScript code to execute when a user selects some of the text in the
text element.
SIZE="lengthChars" specifies the length of the input field, in characters.
VALUE="text" specifies the initial value of the text element.
Example
<P>Last name:
<INPUT TYPE="text" NAME="last_name" VALUE="" SIZE="25">
MULTIPLE specifies that multiple items can be selected. If this attribute is omitted, only one item can
be selected from the list. If multiple selection is enabled, the user usually needs to hold down the Shift
key to select additional items.
NAME="selectName" specifies the name of the select element. This value is the name portion of the
name/value pair sent to the invoked CGI program when the form is submitted. The name is not
displayed on the form.
ONBLUR="blurJScode specifies JavaScript code to execute when the select element loses focus.
ONCHANGE="changeJScode" specifies JavaScript code to execute when the select element loses
focus and its value has been modified.
ONCLICK="JScode" specifies JavaScript code to execute when a user clicks an item in the list.
ONFOCUS="focusJScode" specifies JavaScript code to execute when the element gets focus.
SIZE="ListLength" specifies the number of options visible when the form is displayed. If the list
contains more options than specified by size, the list is displayed with scrollbars.
Used WithinFORM
Select Example 1:Single Item Selection
<FORM>
<B>Shipping method:</B><BR>
<SELECT>
<OPTION> Standard
<OPTION SELECTED> 2-day
<OPTION> Overnight
</SELECT>
</FORM>
OPTION - (option in a SELECT list) The OPTION tag specifies an option in a selection list. Use the
OPTION tag inside a SELECTION tag. When the form containing the selection list is submitted to the
server, a name/value pair is sent for each selected option in the list. The value portion of an option is the
value of the VALUE attribute, if it has one, otherwise, it is the text that follows the <OPTION> tag.
Syntax
<OPTION
VALUE="optionValue"
SELECTED
>
...
</OPTION>
VALUE="OptionValue" specifies a value that is returned to the server when the option is selected and
the form is submitted. When no VALUE attribute is present, the value returned
is the same as the text following the <OPTION> tag.
SELECTED specifies that the option is selected by default.
Used within FOR
Example See example 1:Single Item Selection.
The intent is that when the user enters text into the text entry field and presses the Return key (or
clicks an appropriate button on the browser), the CGI program is invoked again, with the arguments
generated from the data in the text field. The browser outputs a new page whose content is determined by
what the user entered in the text field.
The CGI program should test for the presence of arguments. If there are none, it should display a
default page that includes the ISINDEX tag in the header. If there are arguments, the script does whatever
it needs to do. The string entered by the user is the first argument, and the language your script uses
determines how you access the first argument.
It is beyond the scope of this reference to provide details on CGI programming, but many fine
books are available on the subject, and lots of information is available on the web.
Syntax
<ISINDEX PROMPT="text" >
PROMPT="text" specifies the text that appears as the search prompt in the browser.
Example
The following snippet of code from a CGI program generates the header for an HTML page. When
the page is displayed, it has a text entry field whose prompt is "Enter a search keyword:".
UNIT - II
Client Side Programming : JavaScript
<html>
<head>
<script type="text/javascript">
document.writeln(“Helo World!);
------
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353
</script> WEB TECHNOLOGY
</head>
<body>
----
----
</body>
</html>
To insert a JavaScript into an HTML page, we use the <script> tag. Inside the <script> tag we use the type attribute to
define the scripting language.
So, the <script type="text/javascript"> and </script> tells where the JavaScript starts and ends. It is possible to have
script code inside the body tag also as shown below. If it is placed inside the body tag, the script will be executed
when the content of HTML document is displayed.
<html>
www.Vidyarthiplus.com
<body>
<script type="text/javascript">
............
</script>
</body>
</html>
The document.write command is a standard JavaScript command for writing output to a page. By entering the
document.write command between the <script> and </script> tags, the browser will recognize it as a JavaScript
command and execute the code line. In this case the browser will write Hello World! to the page:
Scripts in <head>
Scripts to be executed when they are called, or when an event is triggered, are placed in functions. It is a good practice
to put all your functions in the head section, this way they are all in one place and do not interfere with page content.
Example
<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event");
}
</script>
</head>
<body onload="message()">
</body>
</html>
JavaScripts in a page will be executed immediately while the page loads into the browser. This is not always what we
want. Sometimes we want to execute a script when a page loads, or at a later event, such as when a user clicks a
button. When this is the case we put the script inside a function
You can place an unlimited number of scripts in your document, and you can have scripts in both the body and the
head section at the same time.
Example
<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event");
}
</script>
</head>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
<body onload="message()">
<script type="text/javascript">
document.write("This message is written by JavaScript");
</script>
</body>
</html>
JavaScript can also be placed in external files. External JavaScript files often contains code to be used on several
different web pages. External JavaScript files have the file extension .js. External script cannot contain the
<script></script> tags. To use an external script, point to the .js file in the "src" attribute of the <script> tag:
Example
<html>
<head>
<script type="text/javascript" src="xxx.js"></script>
</head>
<body>
</body>
</html>
JavaScript Variables
JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more
descriptive name, like carname. Rules for JavaScript variable names:
Variable names are case sensitive (y and Y are two different variables)
Variable names must begin with a letter or the underscore character
Creating variables in JavaScript is most often referred to as "declaring" variables. You can declare JavaScript
variables with the var keyword:
var x;
var carname;
After the declaration shown above, the variables are empty (they have no values yet). However, you can also assign
values to the variables when you declare them:
var x=5;
var carname="Volvo";
After the execution of the statements above, the variable x will hold the value 5, and carname will hold the value
Volvo.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
Assigning Values to Undeclared JavaScript Variables
If you assign values to variables that have not yet been declared, the variables will automatically be declared. These
statements:
x=5;
carname="Volvo"; have
var x=5;
var carname="Volvo";
If you redeclare a JavaScript variable, it will not lose its original value.
var x=5;
var x;
After the execution of the statements above, the variable x will still have the value of 5. The value of x is not reset
(or cleared) when you redeclare it.
If you declare a variable within a function, the variable can only be accessed within that function. When you exit the
function, the variable is destroyed. These variables are called local variables. You can have local variables with the
same name in different functions, because each is recognized only by the function in which it is declared.
If you declare a variable outside a function, all the functions on your page can access it. The lifetime of these
variables starts when they are declared, and ends when the page is closed.
Arithmetic operators are used to perform arithmetic between variables and/or values. Given that y=5, the table
below explains the arithmetic operators:
Assignment operators are used to assign values to JavaScript variables. Given that x=10 and y=5, the table below
explains the assignment operators:
SCE DEPT OF
CSE
www.Vidyarthiplus.com
Operator Example Same As Result
= x=y x=5
+= x+=y x=x+y x=15
-= x-=y x=x-y x=5
*= x*=y x=x*y x=50
/= x/=y x=x/y x=2
%= x%=y x=x%y x=0
Comparison Operators Comparison operators are used in logical statements to determine equality or difference
between variables or values. Given that x=5, the table below explains the comparison operators:
Logical Operators
Logical operators are used to determine the logic between variables or values. Given that x=6 and y=3, the table
below explains the logical operators:
Conditional Operator
JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
Syntax
variablename=(condition)?value1:value2
Example
greeting=(visitor=="PRES")?"Dear President ":"Dear ";
Conditional Statements
Very often when you write code, you want to perform different actions for different decisions. You can use
conditional statements in your code to do this.
if statement - use this statement to execute some code only if a specified condition is true
www.Vidyarthiplus.com
if...else statement - use this statement to execute some code if the condition is true and another code if the
condition is false
if...else if....else statement - use this statement to select one of many blocks of code to be executed
switch statement - use this statement to select one of many blocks of code to be executed
If Statement
Use the if statement to execute some code only if a specified condition is true.
Syntax
if (condition)
{
code to be executed if condition is true
}
Note that if is written in lowercase letters. Using uppercase letters (IF) will generate a JavaScript error!
Example
<script type="text/javascript">
//Write a "Good morning" greeting if
//the time is less than 10
if (time<10)
{
document.write("<b>Good morning</b>");
}
</script>
If...else Statement
Use the if....else statement to execute some code if a condition is true and another code if the condition is not true.
Syntax
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
Example
<script type="text/javascript">
//If the time is less than 10, you will get a "Good morning" greeting.
//Otherwise you will get a "Good day" greeting.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
var d = new Date();
var time = d.getHours();
Use the if....else if...else statement to select one of several blocks of code to be executed.
Syntax
if (condition1)
{
code to be executed if condition1 is true
}
else if (condition2)
{
code to be executed if condition2 is true
}
else
{
code to be executed if condition1 and condition2 are not true
}
Example
script type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time<10)
{
document.write("<b>Good morning</b>");
}
else if (time>10 && time<16)
{
document.write("<b>Good day</b>");
}
else
{
document.write("<b>Hello World!</b>");
}
</script>
Use the switch statement to select one of many blocks of code to be executed.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
Syntax
switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
Alert Box
An alert box is often used if you want to make sure information comes through to the user. When an alert box pops
up, the user will have to click "OK" to proceed.
Syntax
alert("sometext");
Example
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("I am an alert box!");
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Show alert box" />
</body>
</html>
Confirm Box
A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user
will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks
"Cancel", the box returns false.
Syntax
confirm("sometext");
Example
SCE DEPT OF
CSE
www.Vidyarthiplus.com
<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button");
if (r==true)
{
alert("You pressed OK!");
}
else
{
alert("You pressed Cancel!");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_confirm()" value="Show confirm box" />
</body>
</html>
Prompt Box
A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops
up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks
"OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
Syntax
prompt("sometext","defaultvalue");
Example
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","Harry Potter");
if (name!=null && name!="")
{
document.write("Hello " + name + "! How are you today?");
}
}
</script>
</head>
<body>
</body>
</html>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
JavaScript Functions
JavaScript Functions
To keep the browser from executing a script when the page loads, you can put your script into a function. A function
contains code that will be executed by an event or by a call to the function. You may call a function from anywhere
within a page (or even from other pages if the function is embedded in an external .js file). Functions can be defined
both in the <head> and in the <body> section of a document. However, to assure that a function is read/loaded by the
browser before it is called, it could be wise to put functions in the <head> section.
Syntax
function functionname(var1,var2,...,varX)
{
some code
}
The parameters var1, var2, etc. are variables or values passed into the function. The { and the } defines the start and
end of the function. The word function must be written in lowercase letters, otherwise a JavaScript error occurs! Also
note that you must call a function with the exact same capitals as in the function name
Example
<html>
<head>
<script type="text/javascript">
function displaymessage()
{
alert("Hello World!");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="displaymessage()" />
</form>
</body>
</html>
The return statement is used to specify the value that is returned from the function. So, functions that are going to
return a value must use the return statement. The example below returns the product of two numbers (a and b):
Example
<html>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB
TE
<head>
<script type="text/javascript">
function product(a,b)
{
return a*b;
}
</script>
</head>
<body>
<script type="text/javascript">
document.write(product(4,3));
</script>
</body>
</html>
JavaScript Loops
Often when you write code, you want the same block of code to run over and over again in a row. Instead of adding
several almost equal lines in a script we can use loops to perform a task like this.
The for loop is used when you know in advance how many times the script should run.
Syntax
for (variable=startvalue;variable<=endvalue;variable=variable+increment)
{
code to be executed
}
Example
The example below defines a loop that starts with i=0. The loop will continue to run as long as i is less than, or equal to
5. i will increase by 1 each time the loop runs.
Note: The increment parameter could also be negative, and the <= could be any comparing statement.
Example
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
www.Vidyarthiplus.com
www.Vidyarthiplus.com
Loops execute a block of code a specified number of times, or while a specified condition is true.
The while loop loops through a block of code while a specified condition is true.
Syntax
while (variable<=endvalue)
{
code to be executed
}
Example
The example below defines a loop that starts with i=0. The loop will continue to run as long as i is less than, or equal to
5. i will increase by 1 each time the loop runs:
Example
<html>
<body>
<script type="text/javascript">
var i=0;
while (i<=5)
{
document.write("The number is " + i);
document.write("<br />");
i++;
}
</script>
</body>
</html>
The do...while loop is a variant of the while loop. This loop will execute the block of code ONCE, and then it will
repeat the loop as long as the specified condition is true.
Syntax
www.Vidyarthiplus.com
www.Vidyarthiplus.com
D
C
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
do
{
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
code to be executed
}
while (variable<=endvalue);
Example
The example below uses a do...while loop. The do...while loop will always be executed at least once, even if the
condition is false, because the statements are executed before the condition is tested:
Example
<html>
<body>
<script type="text/javascript">
var i=0;
do
{
document.write("The number is " + i);
document.write("<br />");
i++;
}
while (i<=5);
</script>
</body>
</html>
The break statement will break the loop and continue executing the code that follows after the loop (if any).
Example
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++)
{
if (i==3)
{
break;
}
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
The continue statement will break the current loop and continue with the next value.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Example
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3)
{
continue;
}
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>
The for...in statement loops through the elements of an array or through the properties of an object.
Syntax
for (variable in object)
{
code to be executed
}
Note: The code in the body of the for...in loop is executed once for each element/property.
Note: The variable argument can be a named variable, an array element, or a property of an object.
Example
Example
<html>
<body>
<script type="text/javascript">
var x;
var mycars = new Array();
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";
for (x in mycars)
{
document.write(mycars[x] + "<br />");
DEPT
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
}
</script>
</body>
</html>
JavaScript Events
Events are actions that can be detected by JavaScript.
Events
By using JavaScript, we have the ability to create dynamic web pages. Events are actions that can be detected by
JavaScript. Every element on a web page has certain events which can trigger a JavaScript. For example, we can use
the onClick event of a button element to indicate that a function will run when a user clicks on the button. We define
the events in the HTML tags.
Examples of events:
A mouse click
A web page or an image loading
Mousing over a hot spot on the web page
Selecting an input field in an HTML form
Submitting an HTML form
A keystroke
Events are normally used in combination with functions, and the function will not be executed before the
event occurs.
Event Association
Events are associated with HTML tags. The definitions of the events described below are as follows:
www.Vidyarthiplus.com
www.Vidyarthiplus.com
onBlur Button, Checkbox, Password, Radio, Reset, The object in question loses focus (e.g. by
Select, Submit, Text, TextArea, Window clicking outside it or pressing the TAB key).
onChange Select, Text, TextArea The data in the form element is changed by the
user.
onClick Button, Checkbox, Link, Radio, Reset, Submit The object is clicked on.
onFocus Button, Checkbox, Password, Radio, Reset, The object in question gains focus (e.g. by
onKeyPress Image, Link, TextArea The user presses or holds down a key.
onMouseOut Image, Link The user moves the mouse away from the
object.
onMouseOver Image, Link The user moves the mouse over the object.
onSelect Text, Textarea The user selects text within the field.
DEPT OF
CSE
JavaScript Objects
Object oriented Programming in an important aspect of JavaScript. It is possible to use built-in objects available in
JavaScript. It is also possible for a JavaScript programmer to define his own objects and variable types. In this
JavaScript tutorial, you will learn how to make use of built-in objects available in JavaScript.
Date
Math
String, Number, Boolean
RegExp
window (Global Obejct)
Of the above objects, the most widely used one is the String object. Objects are nothing but special kind of data.
Each object has Properties and Methods associated with it. property is the value that is tagged to the object. For
example let us consider one of the properties associated with the most popularly used String object - the length
property. Length property of the string object returns the length of the string that is in other words the number of
characters present in the string.
General syntax of using the length property of the string object is as below:
variablename.length
Here variablename is the name of the variable to which the string is assigned and length is the keyword.
<html>
<body>
<script type="text/javascript">
var exf="Welcome"
document.write(exf.length)
</script>
</body>
</html>
Method of an Object:
Method of an object refers to the actions than can be performed on the object. For example in String Object there are
several methods available in JavaScript.
www.Vidyarthiplus.com
In the example below, we have used toUpperCase method of String object.
<html>
<body>
<script type="text/javascript">
var exf="Welcome"
document.write(exf.toUpperCase())
</script>
</body>
</html>
WELCOME
In the above script since the method toUpperCase is applied to the string object exf which has value initialized as
Welcome all letters get converted as upper case and hence the output is as above.
The main purpose of String Object in JavaScript is for storing text. General method of using String Object is to
declare a variable and assign a string, in other words a text to the variable.
var exf="Welcome"
Method Description
charAt() Returns the character at the specified index
charCodeAt() Returns the Unicode of the character at the specified index
concat() Joins two or more strings, and returns a copy of the joined strings
indexOf() Returns the position of the first found occurrence of a specified value in a string
lastIndexOf() Returns the position of the last found occurrence of a specified value in a string
match() Searches for a match between a regular expression and a string, and returns the matches
Searches for a match between a substring (or regular expression) and a string, and replaces
replace()
the matched substring with a new substring
Searches for a match between a regular expression and a string, and returns the position of
search()
the match
slice() Extracts a part of a string and returns a new string
split() Splits a string into an array of substrings
Extracts the characters from a string, beginning at a specified start position, and through the
substr()
specified number of character
substring() Extracts the characters from a string, between two specified indices
toLowerCase() Converts a string to lowercase letters
toUpperCase() Converts a string to uppercase letters
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Date object of Java Script is used to work with date and times. General syntax for defining Date object in Java Script is
as follows:
In the above new is a keyword which creates an instance of object and Date() defines variablename as Date Object.
For example:
In the above example, variable exf is defined as Date object which has current date and time as its initial value.
setSeconds()- Sets the seconds for a specified date according to local time.
setMinutes() - Sets the minutes for a specified date according to local time.
setHours() - Sets the hours for a specified date according to local time. setDate() -
Sets the day of the month for a specified date according to local time. setMonth() -
Sets the month for a specified date according to local time.
setYear() - Sets the year (deprecated) for a specified date according to local time.
setFullYear() - Sets the full year for a specified date according to local time.
toString() - Returns a string representing the specified Date object.
getSeconds() - Returns seconds in the specified date according to local time.
getMinutes() - Returns minutes in the specified date according to local time.
getHours() - Returns hour in the specified date according to local time. getDay()
- Returns day of the week for a specified date according to local time
getDate() - Returns day of the month for a specified date according to local time.
getMonth() - Returns month in the specified date according to local time. getYear()
- Returns year (deprecated) in the specified date according to local time.
getFullYear() - Returns year of the specified date according to local time.
exf.setFullYear(2020,0,20)
As we have seen setFullYear() is used for Setting the full year for a specified date according to local time. In the
above example the Date object exf is set to the specific date and year 20th January 2020
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<html>
<body>
<script type="text/javascript">
var exforsys=new Date();
var currentDay=exforsys.getDate();
var currentMonth=exforsys.getMonth() + 1;
var currentYear=exforsys.getFullYear();
document.write(currentMonth + "/" + currentDay +
"/" + currentYear);
</script>
</body>
</html>
11/15/2006
JavaScript Math object is used to perform mathematical tasks. But unlike the String and the Date object which
requires defining the object, Math object need not be defined. Math object in JavaScript has two main attributes:
Properties
Methods
The JavaScript has eight mathematical values and this can be accessed by using the Math Object. The eight
mathematical values are:
E
PI
square root of 2 denoted as SQRT2
square root of 1/2 denoted as SQRT1_2
natural log of 2 denoted as LN2
natural log of 10 denoted as LN10
base-2 log of E denoted as LOG2E
base-10 log of E denoted as LOG10E
The way of accessing these values in JavaScript is by using the word Math before these values namely as
Math.E
Math.LOG10E and so on
There are numerous methods available in JavaScript for Math Object. Some of them are mentioned below namely:
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<html>
<body>
<script type="text/javascript">
document.write(Math.round(5.8))
</script>
</body>
</html>
This is because the round() method rounds the number given in argument namely here 5.8 to the nearest integer. It
rounds .5 up which gives 6.
<html>
<body>
<script type="text/javascript">
document.write(Math.max(8,9) + "<br />")
document.write(Math.max(-5,3) + "<br />")
document.write(Math.max(-2,-7) + "<br />")
</script>
</body>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
</html>
9
3
-2
The above example uses the max() method of the Math object which returns the largest of the two numbers given in
arguments of the max method.
The Boolean object is used to convert a non-Boolean value to a Boolean value (true or false).
Method Description
toString() Converts a Boolean value to a string, and returns the result
valueOf() Returns the primitive value of a Boolean object
Number Object
Syntax
Method Description
toExponential(x) Converts a number into an exponential notation
toFixed(x) Formats a number with x numbers of digits after the decimal point
toPrecision(x) Formats a number to x length
toString() Converts a Number object to a string
valueOf() Returns the primitive value of a Number object
String Object
Syntax
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
or more simply:
Window Object
If a document contain frames (<frame> or <iframe> tags), the browser creates one window object for the HTML
document, and one additional window object for each frame.
Method Description
alert() Displays an alert box with a message and an OK button
blur() Removes focus from the current window
clearInterval() Clears a timer set with setInterval()
clearTimeout() Clears a timer set with setTimeout()
close() Closes the current window
confirm() Displays a dialog box with a message and an OK and a Cancel button
createPopup() Creates a pop-up window
focus() Sets focus to the current window
moveBy() Moves a window relative to its current position
moveTo() Moves a window to the specified position
open() Opens a new browser window
print() Prints the content of the current window
prompt() Displays a dialog box that prompts the visitor for input
resizeBy() Resizes the window by the specified pixels
resizeTo() Resizes the window to the specified width and height
scroll()
scrollBy() Scrolls the content by the specified number of pixels
scrollTo() Scrolls the content to the specified coordinates
setInterval() Calls a function or evaluates an expression at specified intervals (in milliseconds)
setTimeout() Calls a function or evaluates an expression after a specified number of milliseconds
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Assuming you know the regular expression pattern you are going to use, there is no real difference between the two;
however, if you don't know the pattern ahead of time (e.g, you're retrieving it from a form), it can be easier to use the
RegExp() constructor.
The regular expression method in JavaScript has two main methods for testing strings: test() and exec().
The exec() Method
The exec() method takes one argument, a string, and checks whether that string contains one or more matches of the
pattern specified by the regular expression. If one or more matches is found, the method returns a result array with the
starting points of the matches. If no match is found, the method returns null.
The test() method also takes one argument, a string, and checks whether that string contains a match of the pattern
specified by the regular expression. It returns true if it does contain a match and false if it does not. This method is
very useful in form validation scripts. The code sample below shows how it can be used for checking a social
security number. Don't worry about the syntax of the regular expression itself. We'll cover that shortly.
function f1(ssn)
{
if (exp.test(ssn)) { alert("VALID SSN"); }
else { alert("INVALID SSN"); }
}
</script>
</head>
<body>
<form name=”f1”>
<input type="text" name="t1" />
<input type="button" value="Check" onclick="f1(this.f1.t1.value);" />
</form>
</body>
</html>
Code Explanation
1. First, a variable containing a regular expression object for a social security number is
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
2. Next, a function called f1() is created. This function takes one argument: ssn, which is a string. The function
then tests to see if the string matches the regular expression pattern by passing it to the regular expression object's
test() method. If it does match, the function alerts "VALID SSN". Otherwise, it alerts "INVALID SSN".
function f1(ssn)
{
if (exp.test(ssn)) { alert("VALID SSN"); } else
{ alert("INVALID SSN"); }
}
3. A form in the body of the page provides a text field for inserting a social security number and a button
that passes the user-entered social security number to the f1() function.
<form >
<input type="text" name="t1" />
<input type="button" value="Check" onclick="checkSsn(this.form.ssn.value);" />
</form>
Flags
Flags appearing after the end slash modify how a regular expression works.
* The i flag makes a regular expression case insensitive. For example, /aeiou/i matches all lowercase and
uppercase vowels.
* The g flag specifies a global match, meaning that all matches of the specified pattern should be
A caret (^) at the beginning of a regular expression indicates that the string being searched must start with this
pattern.
A dollar sign ($) at the end of a regular expression indicates that the string being searched must end with this
pattern.
Number of Occurrences : ? + * {}
The following symbols affect the number of occurrences of the preceding character: ?, +, *, and {}.
A questionmark (?) indicates that the preceding character should appear zero or one times in the pattern.
* The pattern foo? can be found in "food" and "fod", but not "faod".
A plus sign (+) indicates that the preceding character should appear one or more times in the pattern. *
The pattern fo+ can be found in "fod", "food" and "foood", but not "fd".
A asterisk (*) indicates that the preceding character should appear zero or more times in the pattern.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Curly brackets with one parameter ( {n} ) indicate that the preceding character should appear exactly n times in the
pattern.
* The pattern fo{3}d can be found in "foood" , but not "food" or "fooood".
Curly brackets with two parameters ( {n1,n2} ) indicate that the preceding character should appear between n1 and
n2 times in the pattern.
* The pattern fo{2,4}d can be found in "food","foood" and "fooood", but not "fod" or "foooood".
Curly brackets with one parameter and an empty second paramenter ( {n,} ) indicate that the preceding character
should appear at least n times in the pattern.
* The pattern fo{2,}d can be found in "food" and "foooood", but not "fod".
Common Characters: . \d \D \w \W \s \S
* The pattern fo.d can be found in "food", "foad", "fo9d", and "fo*d".
* The pattern fo\dd can be found in "fo1d", "fo4d" and "fo0d", but not in "food" or "fodd".
* The pattern fo\Dd can be found in "food" and "foad", but not in "fo4d".
Backslash-w ( \w ) represents any word character (letters, digits, and the underscore (_) ).
* The pattern fo\wd can be found in "food", "fo_d" and "fo4d", but not in "fo*d".
* The pattern fo\Wd can be found in "fo*d", "fo@d" and "fo.d", but not in "food".
Backslash-s ( \s) represents any whitespace character (e.g, space, tab, newline, etc.).
* The pattern fo\sd can be found in "fo d", but not in "food". Backslash-
* The pattern fo\Sd can be found in "fo*d", "food" and "fo4d", but not in "fo d".
Grouping: []
* The pattern f[aeiou]d can be found in "fad" and "fed", but not in "food", "faed" or "fd".
* The pattern f[aeiou]{2}d can be found in "faed" and "feod", but not in "fod", "fed" or
"fd". Negation : ^
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
When used after the first character of the regular expression, the caret ( ^ ) is used for negation.
* The pattern f[^aeiou]d can be found in "fqd" and "f4d", but not in "fad" or "fed".
Subpatterns: ()
* The pattern f(oo)?d can be found in "food" and "fd", but not in "fod".
Alternatives: |
* The pattern foo$|^bar can be found in "foo" and "bar", but not
* The pattern fo\.d can be found in "fo.d", but not in "food" or "fo4d".
A more practical example has to do matching the delimiter in social security numbers. Examine the following
regular expression.
Within the caret (^) and dollar sign ($), which are used to specify the beginning and end of the pattern, there are
three sequences of digits, optionally separated by a hyphen or a space. This pattern will be matched in all of
following strings (and more).
* 123-45-6789
* 123 45 6789
* 123456789
* 123-45 6789
* 123 45-6789
* 123-456789
The last three strings are not ideal, but they do match the pattern. Back references can be used to make sure that the
second delimiter matches the first delimiter. The regular expression would look like this.
^\d{3}([\- ]?)\d{2}\1\d{4}$
The \1 refers back to the first subpattern. Only the first three strings listed above match this regular expression.
Regular expressions make it easy to create powerful form validation functions. Take a look at the following
example.
Code Sample: Login.html
<html>
<head>
<script type="text/javascript">
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
function validate()
{
var email = form.Email.value;
var password = form.Password.value;
var errors = [];
if (!RE_EMAIL.test(email)) { alert( "You must enter a valid email address."); }
if (!RE_PASSWORD.test(password)) { alert( "You must enter a valid password."); }
}
</script>
</head>
<body>
<form name=”form”>
Email: <input type="text" name="Email" />
Password: <input type="password" name="Password” />
*Password must be between 6 and 10 characters and can only contain letters and digits.
Code Explanation
This code starts by defining regular expressions for an email address and a password. Let's break each one down.
1. The caret (^) says to start at the beginning. This prevents the user from entering invalid characters at the
beginning of the email address.
2. (\w+[\-\.])* allows for a sequence of word characters followed by a dot or a dash. The * indicates that the
pattern can be repeated zero or more times. Successful patterns include "ndunn.", "ndunn-", "nat.s.", and "nat-
s-".
3. \w+ allows for one or more word characters.
4. @ allows for a single @ symbol.
5. (\w+\.)+ allows for a sequence of word characters followed by a dot. The + indicates that the pattern can be
repeated one or more times. This is the domain name without the last portion (e.g, without the "com" or "gov").
6. [A-Za-z]+ allows for one or more letters. This is the "com" or "gov" portion of the email address.
7. The dollar sign ($) says to end here. This prevents the user from entering invalid characters at the end of the
email address.
1. The caret (^) says to start at the beginning. This prevents the user from entering invalid characters at the
beginning of the password.
2. [A-Za-z\d]{6,8} allows for a six- to eight-character sequence of letters and digits.
3. The dollar sign ($) says to end here. This prevents the user from entering invalid characters at the end of the
password.
Exercises:
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
1. Construct a reg exp to validate a text field which should be used to accept only a string composed by 3
letters, one space, 6 numbers, a "-" and a number such as MJHJ 123456-6
Ans: /^[A-Za-z]{4}\s\d{6}\-\d{1}$/
Document Object
Each HTML document loaded into a browser window becomes a Document object. The Document object provides
access to all HTML elements in a page, from within a script.
Method Description
close() Closes the output stream previously opened with document.open()
getElementById() Accesses the first element with the specified id
getElementsByName() Accesses all elements with a specified name
getElementsByTagName() Accesses all elements with a specified tagname
Opens an output stream to collect the output from document.write() or
open()
document.writeln()
write() Writes HTML expressions or JavaScript code to a document
writeln() Same as write(), but adds a newline character after each statement
Arrays
It describes the JavaScript array object including parameters, properties, and methods.
Parameters
* arrayLength
* elementN - Array element list of values
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Properties
* index
* input
* length - The quantity of elements in the object.
* prototype - For creating more properties.
Methods
* chop() - Used to truncate the last character of a all strings that are part of an array. This method is not defined so it
must be written and included in your code.
Look out
Duck
* concat()
* grep(searchstring) - Takes an array and returns those array element strings that contain matching strings. This
method is not defined so it must be written and included in your code.
lines, finish
* join(delimiter) - Puts all elements in the array into a string, separating each element with the specified delimiter.
limit;lines;finish;complete;In;Out
* pop() - Pops the last string off the array and returns it. This method is not defined so it must be written
and included in your code.
Out
* push(strings) - Strings are placed at the end of the array. This method is not defined so it must be written and
included in your code.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
* shift() - Decreases array element size by one by shifting the first element off the array and returning it.
This method is not defined so it must be written and included in your code.
Out
*sort() - Sorts the array elements in dictionary order or using a compare function passed to the method.
In,Out,complete,finish,limit,lines
* splice() - It is used to take elements out of an array and replace them with those specified. In the below example
the element starting at element 3 is removed, two of them are removed and replaced with the specified strings. The
value returned are those values that are replaced. This method is not defined so it must be written and included in
your code.
complete, In
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353
WEB TECHNOLOGY
Form validation
Form validation is the process of checking that a form has been filled in correctly before it is processed. For example, if
your form has a box for the user to type their email address, you might want your form handler to check that they've
filled in their address before you deal with the rest of the form. Form validation is usually done with JavaScript
embedded in the Web page
The above program will accept the input in any one of the following valid form
raj@yahoo.com raj.kumar@yahoo.com raj.k@yahoo.co.in
SCE
DEPT OF
CSE
www.Vidyarthiplus.com
The above program will accept the input only in the following valid form
Rajkumar
The above program will accept the input only in any one of the following valid form
25 5 101
Validate a checkbox
Validate form selection
DEPT OF
UNIT - III
Host Objects
JavaScript supports three types of objects: native, host, and user-defined. Native objects are objects
supplied by the JavaScript language. String, Boolean, Math, and Number are examples of native objects.
Host objects are JavaScript objects that provide special access to the host environment. They are provided
by the browser for the purpose of interaction with the loaded document. In a browser environment,
1. window
2. document
objects are host objects. Several other browser host objects are informal, de facto standards. They are: alert,
prompt, confirm.
DOM
• The Document Object Model (DOM) is an API that allows programs to interact with HTML (or
XML) documents
• The primary function of the Document Object Model is to view, access, and change the structure
of an HTML document separate from the content contained within it.
• The DOM will provide you with methods and properties to retrieve, modify, update, and delete
parts of the document you are working on. The properties of the Document Object Model are used
to describe the web page or document and the methods of the Document Object Model are used
for working with parts of the web page.
• In DOM, HTML document is represented in tree like structure. It constructs a hierarchical tree
structure for a HTML document to traverse and to manipulate the document.
• For example,
<html>
<head>
<title>Sample Document</title>
</head>
<body>
<h1>An HTML Document</h1>
<p>This is a <i>simple</i> document.
</body>
</html>
DEPT OF
The node directly above a node is the parent of that node. The nodes one level directly below another node
are the children of that node. Nodes at the same level, and with the same parent, are siblings. The set of
nodes any number of levels below another node are the dendants of that node.
Types of nodes
• There are many types of nodes in the DOM document tree that specifies what kind of node it
is. Every Object in the DOM document tree has properties and methods defined by the Node
host object.
The following table lists the non method properties of Node object.
DEPT OF
www.Vidyarthiplus.com
The following table lists the node types commonly encountered in HTML documents and the nodeType
value for each one.
SCE
DEPT OF
CSE
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
The DOM represents an HTML document as a tree of Node objects. With any tree structure, one of the
most common things to do is traverse the tree, examining each node of the tree in turn. The following
program shows one way to do this.
<html>
<head>
<script>
function countTags(n)
{ // n is a Node
var numtags = 0; // Initialize the tag counter
if (n.nodeType == 1 ) // Check if n is an Element
numtags++; // Increment the counter if so
var children = n.childNodes; // Now get all children of n
for(var i=0; i < children.length; i++)
{ // Loop through the children
numtags += countTags(children[i]); // Recurse on each one
}
return numtags; // Return the total number of tags
}
</script>
</head>
<body onload="alert('This document has ' + countTags(document) + ' tags')">
This is a <i>sample</i> document.
</body>
</html>
Output
The ability to traverse all nodes in a document tree gives us the power to find specific nodes. When
programming with the DOM API, it is quite common to need a particular node within the document or a
list of nodes of a specific type within the document.
You can use getElementById() and getElementsByTagName( ) methods of Document Object to obtain a
list of any type of HTML element. For example, to find all the tables within a document, you'd do this:
DEPT OF
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
This code finds <table> tags and returns elements in the order in which they appear in the document.
<html>
<head>
<script type="text/javascript">
function f1()
{
alert(document.getElementById("p1").nodeName);
}
</script>
</head>
<body>
<p id="p1"> Program is coded to find paragraph element is present in the document or not using
its id attribute</p>
<input type="button" value="Find" onclick="f1();" />
</body>
</html>
Output
In the above program the method getElementById() finds the specific element and nodeName is used
property return the specific element name.
DOM API lies in the features that allow you to use JavaScript to dynamically modify documents. The
following examples demonstrate the basic techniques of modifying documents and illustrate some of the
possibilities.
The following example includes a JavaScript function named reverse( ), a sample document, and an HTML
button that, when pressed, calls the reverse( ) function, passing it the node that represents the <body> element
of the document. The reverse( ) function loops backward through the children of the supplied node and uses
the removeChild( ) and appendChild( ) methods of the Node object to reverse the order of those children.
<html>
<head><title>Reverse</title>
<script>
function reverse(n) { // Reverse the order of the children of Node n
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
when the user clicks the button, the order of the paragraphs and of the button are reversed.
The following program illustrates how to change the element style using DOM properties and methods.
<html>
<head>
<script type="text/javascript">
function f1()
{
document.getElementById("p1").style.backgroundColor="red";
}
</script>
</head>
<body>
<p id="p1"> Program is coded to change the style of the paragraph</p>
<input type="button" value="Change" onclick="f1();" />
DEPT OF
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
</body>
</html>
The method getElementById() gets the paragraph element in the document and the property style is used to
change the background color of the paragraph to “red” as shown below.
<html>
<head>
<script type="text/javascript">
function f1()
{
var o=document.getElementById("p1");
o.style.color="red";
}
function f2()
{
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 var o=document.getElementById("p1"); WEB TECHNOLOGY
o.style.color="blue";
}
</script>
</head>
<body>
<p id="p1"> Click
Me
</p>
<form>
<input type=button id="b1" value="RED" onclick=f1() />
<input type=button id="b2" value="BLUE" onclick=f2() />
</form>
</body>
</html>
Output
www.Vidyarthiplus.com
<html>
<head>
<script type="text/javascript">
function f1()
{
After pressing the Question button, it adds the content, How are you?” to the HTML document and after
pressing the Answer button, it replaces the content “How are you?” with “Fine, thank you”
<html>
<head>
<script type="text/javascript">
function f1()
{
var node=document.getElementById("p1");
node.removeChild(node.childNodes[0]);
}
</script>
</head>
<body >
<pre id="p1"><input type="button" id="b1" value="Question" />
<input type="button" id="b2" value="Remove" onclick=f1() />
Example for Removing an element from HTML document. </pre>
</body>
</html>
After pressing the “Remove” button, the element “Question” is removed from the document.
DEPT OF
www.Vidyarthiplus.com
The combination of
HTML
JavaScript
DOM
is sometimes referred to as Dynamic HTML (DHTML). Web pages that include scripting are often called
dynamic pages. Similarly, web server response can be static or dynamic
Static: HTML document is retrieved from the file system by the server and the same
returned to the client.
Dynamic: In server, a HTML document is generated by a program in response to an
HTTP request
Java servlets are one technology for producing dynamic server responses. Servlet is a class instantiated by
the server to produce a dynamic response.
Servlet Overview
SCE
DEPT OF
CSE
www.Vidyarthiplus.com
Types of Servlet
Generic Servlet
HttpServlet
Java Servlets are programs that run on a Web or Application server and act as a middle layer between a
request coming from a Web browser or other HTTP client and databases or applications on the HTTP
server.
Using Servlets, you can collect input from users through web page forms, present records from a database
or another source, and create web pages dynamically.
Java Servlets often serve the same purpose as programs implemented using the Common Gateway Interface
(CGI). But Servlets offer several advantages in comparison with the CGI.
Servlets Architecture:
www.Vidyarthiplus.com
www.Vidyarthiplus.com
Servlets Tasks:
1. Read the explicit data sent by the clients (browsers). This includes an HTML form on a Web page
or it could also come from an applet or a custom HTTP client program.
2. Read the implicit HTTP request data sent by the clients (browsers). This includes cookies, media
types and compression schemes the browser understands, and so forth.
3. Process the data and generate the results. This process may require talking to a database, executing
an RMI or CORBA call, invoking a Web service, or computing the response directly.
4. Send the explicit data (i.e., the document) to the clients (browsers). This document can be sent in a
variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc.
5. Send the implicit HTTP response to the clients (browsers). This includes telling the browsers or
other clients what type of document is being returned (e.g., HTML), setting cookies and caching
parameters, and other such tasks.
Servlets Packages:
Java Servlets are Java classes run by a web server that has an interpreter that supports the Java Servlet
specification.
Servlets can be created using the javax.servlet and javax.servlet.http packages, which are a standard part
of the Java's enterprise edition, an expanded version of the Java class library that supports large-scale
development projects.
These classes implement the Java Servlet and JSP specifications. At the time of writing this tutorial, the
versions are Java Servlet 2.5 and JSP 2.1.
Java servlets have been created and compiled just like any other Java class. After you install the servlet
packages and add them to your computer's Classpath, you can compile servlets with the JDK's Java
compiler or any other current compiler.
A servlet life cycle can be defined as the entire process from its creation till the destruction. The
following are the paths followed by a servlet
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
The init method is designed to be called only once. It is called when the servlet is first created,
and not called again for each user request. So, it is used for one-time initializations, just as with
the init method of applets.
The servlet is normally created when a user first invokes a URL corresponding to the servlet, but you
can also specify that the servlet be loaded when the server is first started.
When a user invokes a servlet, a single instance of each servlet gets created, with each user
request resulting in a new thread that is handed off to doGet or doPost as appropriate. The
init() method simply creates or loads some data that will be used throughout the life of the
servlet.
The service() method is the main method to perform the actual task. The servlet container (i.e.
web server) calls the service() method to handle requests coming from the client( browsers) and to
write the formatted response back to the client.
Each time the server receives a request for a servlet, the server spawns a new thread and calls
service. The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and
calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.
The service () method is called by the container and service method invokes doGe, doPost, doPut,
doDelete, etc. methods as appropriate. So you have nothing to do with service() method but you
override either doGet() or doPost() depending on what type of request you receive from the client.
The doGet() and doPost() are most frequently used methods with in each service request. Here are the
signature of these two methods.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
A GET request results from a normal request for a URL or from an HTML form that has no METHOD
specified and it should be handled by doGet() method.
A POST request results from an HTML form that specifically lists POST as the METHOD and it
should be handled by doPost() method.
The destroy() method is called only once at the end of the life cycle of a servlet. This method
gives your servlet a chance to close database connections, halt background threads, write cookie lists
or hit counts to disk, and perform other such cleanup activities.
After the destroy() method is called, the servlet object is marked for garbage collection. The destroy
method definition looks like this:
Architecture Diagram:
First the HTTP requests coming to the server are delegated to the servlet container.
The servlet container loads the servlet before invoking the service() method.
Then the servlet container handles multiple requests by spawning multiple threads, each
thread executing the service() method of a single instance of the servlet.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class NewServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html"); // content type of the response
PrintWriter out = response.getWriter(); // used to create a response as a Html
doc try {
out.println("<html>");
---------------------
---------------------
out.println("</html>");
}catch(Exception e){}
}
}
}
Servlets - Examples
Servlets are Java classes which service HTTP requests and implement the javax.servlet.Servlet interface.
Web application developers typically write servlets that extend javax.servlet.http.HttpServlet, an abstract
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
class that implements the Servlet interface and is specially designed to handle HTTP requests.
DEPT OF
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Following is the sample source code structure of a servlet example to write Hello World:
Output:
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Servlet has methods to access data contained in HTTP Request (URL) sent to the server from the browser.
The Query String portion of the HTTP request is so called parameter data. For example,
http://www.example.com/servlet/PrintThis?name=Raj&color=Red
where the portion after the ? is called a query string. Here it is “name=Raj&color=Red”, in which name and
color are parameter names and “Raj” and “Red” are parameter values. Printthis is a servlet filename and
servelt is a directory. Multiple parameters are separated by &. All parameter values are strings by default.
Parameter names and values can be any 8-bit characters.
The following methods are used to process these parameter data in sevlets.
The following program explains how to process these parameter names and values as well as path of the
resource using servlet.
Example program
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class NewServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html”);
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>"); out.println("<title>Servlet
NewServlet</title>"); out.println("</head>");
out.println("<body>");
out.println("Servlet file NewServlet is at: " + request.getContextPath());
Enumeration para1=request.getParameterNames();
while(para1.hasMoreElements())
{
out.println("Parameter name:"+para1.nextElement());
}
String name = request.getParameter("name");
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
String id = request.getParameter("id");
out.println("Name:" + name);
out.println("Id:" + id);
out.println("</body>");
out.println("</html>");
}catch(Exception e){}
}
}
}
The method getContextPath() of HttpServeltRequest object is used to get the location of the resource
The method getParameter() is used to get the value of the parameter. The method getParameterNames() is
used to return the paranameter names as well. It returns enumeration. The following code in the above
program is used to retrieve the parameter names from the enumeration.
Enumeration para1=request.getParameterNames();
while(para1.hasMoreElements())
{
out.println("Parameter name:"+para1.nextElement());
}
Output:
A form automatically generates a query string when submitted. The parameter name specified by value of
name attributes of form controls. For example,
Parameter value can be the value of value attribute of any form control or it may be the value received from
the user by the control at run time. For example,
The following program explains how to send the data to server from a web page and the same how to
receive it from the server.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<html>
<head>
</head>
<body>
<pre>
<form action="NewServlet" method="post">
First Name: <input type="text" name="t1" />
Last Name: <input type="text" name="t2" />
Age: <input type="text" name="t3" /> E-mail:
<input type="text" name="t4" />
<input type="submit" value="Submit" />
<form>
</pre>
</body>
</html>
Servlet for processing the data coming from this web page
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
out.println("<html>");
out.println("<head>"); out.println("<title>Servlet
NewServlet</title>"); out.println("</head>");
out.println("<body>");
String s1 =
request.getParameter("t1"); String s2
= request.getParameter("t2"); String
s3 = request.getParameter("t3");
String s4 =
request.getParameter("t4");
out.println("First Name:" +
s1); out.println("Last Name:" +
s2); out.println("Age:" + s3);
out.println("E-mail:" + s4);
out.println("</body>");
out.println("</html>");
} catch(Exception e) {}
}
}
Output
www.Vidyarthiplus.com
www.Vidyarthiplus.com
GET:
It is used to process the query string which is part of URL
If the length of query string is limited it may be used.
It is recommended when parameter data is not stored but used only to request
information. POST:
It is used to process the query string as well as to store the data on server.
If the Query string is sent as body of HTTP request, the post method will be used to retrieve.
If the length of query string is unlimited, it can be used
It is recommended if parameter data is intended to cause the server to update stored data
Most browsers will warn you if they are about to resubmit POST data to avoid duplicate updates
Important note:
SCE
DEPT OF
CSE
www.Vidyarthiplus.com
UNIT IV
Representing Web Data: XML-Documents and Vocabularies-Versions and Declaration -
Namespaces JavaScript and XML: Ajax-DOM based XML processing Event-oriented
Parsing: SAX-Transforming XML Documents-Selecting XMLData: PATH-Template-
based Transformations: XSLT-Displaying XML Documents in Browsers-Case Study-
Related Technologies. Separating Programming and Presentation: JSPTechnology Introduction-
JSP and Servlets-Running JSP Applications Basic JSP-JavaBeansClasses and JSP-Tag
Libraries and Files- Support for the Model-View-Controller Paradigm-Case Study-
Related Technologies.
XML
XML stands for eXtensible Markup Language, developed by W3C in 1996. XML 1.0 was
officially adopted as a W3C recommendation in 1998. XML was designed to carry data, not to
display data. XML is designed to be self-descriptive. XML is a subset of SGML that can
define your own tags. A Meta Language and tags describe the content. XML Supports
CSS, XSL, DOM.
www.Vidyarthiplus.com
www.Vidyarthiplus.com
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
XML with correct syntax is "Well Formed" XML. XML validated against a DTD is "Valid" XML.
A "Well Formed" XML document must have the following correct XML syntax:
Xml document begins with XML declaration statement: <? xml version="1.0"
encoding="ISO- 8859-1"?> . The next line describes theroot element of the document:
<note>. This element is "the parent" of all other elements. The next 4 lines describe
4child elements of the root: to, from, heading, and body. And finally the last line defines
the end of the rootelement : < /note>
XML Element
An XML element is everything from (including) the element's start tag to (including) the
element's end tag.
- other elements
- text
- attributes
- Or a mix of all of the above...
XML vocabulary
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
Some of the xml vocabularies are XHTML, RSS, XSL, DTD, and
Document Type Definition purpose is to define the structure of an XML document. It defines
the structure with a list of defined elements in the xml document.
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)> <!ELEMENT
from (#PCDATA)> <!ELEMENT
heading (#PCDATA)> <!ELEMENT
body (#PCDATA)>
]>
Where PCDATA refers parsed character data. In the above xml document the elements to,
from, heading, body carries some text, so that, these elements are declared to carry text in
DTD file.
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
The schema has more advantages over DTD. A DTD can have two types of data in it,
namely the CDATA and the PCDATA. The CDATA is not parsed by the parser whereas
the PCDATA is parsed. In a schema you can have primitive data types and custom data
types like you have used in programming.
XML Parsers
An XML parser converts an XML document into an XML DOM object - which can
then be manipulated with a JavaScript.
– Validating Parser
• It requires document type declaration
• It generates error if document does not
– Conform with DTD and
– Meet XML validity constraints
– Non-validating Parser
• It checks well-formedness for xml document
• It can ignore external DTD
XML Namespaces
It is a collection of element and attributes names associated with an XML vocabulary. XML
Namespaces provide a method to avoid element name conflicts.
XML document 1
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
XML document2
<table>
<name> Coffee Table</name>
<width>80</width>
<length>120</length> </table>
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
If these XML fragments were added together, there would be a name conflict. Both contain a
<table> element, but the elements have different content and meaning. Such name conflicts in
XML can easily be avoided using a name prefix as shown below:
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
When using prefixes in XML, a so-called namespace for the prefix must be defined. The
namespace is defined by the xmlns attribute in the start tag of an element. The
namespace declaration has the following syntax.
xmlns:prefix="URI"
For example,
<h:table xmlns:h="http://www.w3.org/table">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http://www.w3.org/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width> <f:length>120</f:length>
</f:table>
Default namespace
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
RSS
With RSS it is possible to distribute up-to-date web content from one web site to thousands
of other web sites around the world.
RSS allows fast browsing for news and updates. RSS was designed to show selected data.
Distributing your content using RSS will involve creating one file that contains your
content. This file will reside on your server to enable other web sites to display your
channel. You can update your channel simply by updating your file.
Without RSS, users will have to check your site daily for new updates. This may be
too time- consuming for many users. With an RSS feed, they can check your site
faster using an RSS aggregator (a site or program that gathers and sorts out RSS feeds)
since RSS data is small and fast-loading
RSS is useful for web sites that are updated frequently, like:
Your first step will be to identify your file. To do this, place the following code at the top
of your text file.
<?xml version="1.0"?>
<rss version="0.91">
Your next step will be to create your channel header. The "channel" tag indicates that you
are beginning a new channel.
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
<channel>
<title>Web-Source.net Syndication</title>
<link>http://www.web-source.net</link>
<description>Web Development article syndication feeds!</description>
<language>en-us</language>
The "title" tag indicates the name of your channel. The "link" tag will contain a link to
your web site. The "description" tag describes your channel and the "language" tag indicates
that you're writing in US English.
Now, you're ready to create your headlines. Each new "item" tag represents a new topic.
<item>
<title> Creating A Customized Marquee </title>
<link>http://www.example.com/tips.htm</link>
<description>
Learn how to create a customized marquee for your web
</description>
</item>
Your final step will be to close your channel by adding the following tags:
</channel>
</rss>
Save your new file with .rss file extension and upload it to your server. And now,
you're ready to share your content.
AJAX:
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
- AJAX allows updating parts of a web page, without reloading the whole page.
- With Ajax, web applications can also retrieve data from the server asynchronously in
the background without interfering with the display and behavior of the existing
page.
- Ajax is combination of
o HTML
o XML
o CSS
o JavaScript
o JavaScript DOM
o XMLHttpRequest in asynchronous mode
1. Asynchronous
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
This means that when you send a request, you wait for
the response to come back, but are free to do other things
while you wait. The response probably won‟t come back
immediately, so you set up afunction that will wait for the
response to be sent back by the server, and react to it
2. JavaScript once that happens.
The data that you receive back from the server will often
be packaged up as a snippet of XML, so that it can be
easily processed with JavaScript. This data can be anything
How AJAX works? you want, and as long as you want.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
Example
The following AJAX application above contains one div section and one button.
The div section will be used to display information returned from a server. The button calls a
function named loadXMLDoc(), if it is clicked:
<html>
<head>
<script type="text/javascript">
function dataData()
{
var xmlhttp=new XMLHttpRequest(); // create XMLHttpRequest to exchange data with server
var obj= getElementById("myDiv");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
obj=xmlhttp.responseText;
}
}
xmlhttp.open("GET",”data.txt”, true);
xmlhttp.send(); To send a request to server
}
</script>
</head>
<body><form>
</form></body>
</html>
The AJAX application above contains one div section and one button. The div section
will be used to display information returned from a server. Buttoncalls a function named
getData(), if it is clicked. The script section contains the getData() function. The AJAX script
presents inside the getData() function. When a request is sent to server, onreadystatechange
event is triggered. The readystate property holds the status of the XMLHttpRequest. The
readystate=4 means requestis finished and response is ready where as status=200
means “OK”.
When the button is clicked, the content available in the file “data.txt” will be placed inside
the
<div> tag. The existing content “Let AJAX change this text” will be replaced with data.txt
content
XML DOM
Document Object Model is for defining the standard for accessing and
manipulating XML documents. XML DOM is used for
Loading the xml document
Accessing the xml document
Deleting the elements of xml document
Changing the elements of xmldocument
two ways:
Parsing the XML doc. using DOM methods and properties are called as tree based
approach whereas using SAX (Simple Api for Xml) methods and properties are called
as event based approach.
JAXP is a tool, stands for Java Api for Xml Processing, used for accessing and manipulating
xml document in a tree based manner.
In this approach, to access XML document, the document object model implementation is
defined in the following packages:
javax.xml.parsers
org.w3c.dom
The following DOM javaClasses are necessary to process the XML document:
The following methods and properties are necessary to process the XML document:
Property Meaning
nodeName Finding the name of the node
nodeValue Obtaining value of the node
parentNode To get parnet node
childNodes Obtain child nodes
attributes For getting the attributes values
Method Meaning
getElementByTagName(name) To access the element by specifying its name
appendChild(node) To insert a child node
removeChild(node) To remove existing child node
This program takes a file name from the console and checks its availability. If the file exists
then a parser is created using Document Builder. This object parses the givenXML document.
It searches thespecified element name and counts its occurrence in the xml file. If the given
element doesn't exist it displays the '0' element.
Step 2: Create a java based dom for counting the number of elements in xml file.
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
Output:
Number of nodes: 2
The diagram here shows the JAXP APIs to process xml document using the DOM parser:
An XML tree is not viewed as a data structure, but as a stream of events generated by
the parser.
Scanning the XML file from start to end, each event invokes a corresponding callback
method that the programmer writes.
SAX packages
characters() – method called with the text contents in between the start and end
tags of an XML document element.
At the very first, create an instance of the SAXParserFactory class which generates an
instance of the parser. This parser wraps a SAXReader object. When the parser's
parse() method is invoked, the reader invokes one of the several callback methods
(implemented in the application). These callback methods are defined by the
interfaces ContentHandler, ErrorHandler, DTDHandler, and EntityResolver.
<?xml version="1.0"?>
<company>
<staff>
<firstname>Ram</firstname>
<salary>100000</salary>
</staff>
<staff>
<firstname>Kumar</firstname>
<salary>200000</salary>
</staff>
</company>
www.Vidyarthiplus.com
2.Create a Java file.
public classReadXMLFileSAX
{
try{
{ booleanbfname = false;
booleanbsalary = false;
if (bsalary)
{
System.out.println("Salary : " + new String(ch, start, length));
bsalary = false;
}
}
}
saxParser.parse("c:\\file.xml", handler);
} catch(Exception e) { }
}
}
Result
SAX DOM
Event based model Tree data structure
Serial access Random access
Low memory usage High memory usage
Used to process parts of the document Used to edit the document
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
It is process of extracting one info. From one xml doc. and uses that info to create
another xml doc.
XSL
XSL is stands for eXtensible Style sheet Language which is an xml vocabulary. It contains
two types of information:
Template data: Which is text that is copied to output xml document with change or no
1. XSLT
2. XPATH
3. XSL-FO
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
XPATH- is used to find information in an XML document. It navigates through elements and
attributes in XML documents.
XSL-FO is a XSL Formatter an xml vocabulary for defining style properties of xml document.
b. Xslt style sheet that defines the information of source xml program to be transformed
The JAXP is a tool which is used as XSLT processor. The XSLT processor receives xslt
and xml program as its input and generates another xml program as its output where
we can see the content retrieved from source xml program
Package Description
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
You can refer lab experiment also
Example for XSLT
Step 3: Create XML Transformer program in java and give input both .xml and .xsl file
SCE DEPT OF
CSE
www.Vidyarthiplus.com
import javax.xml.transform.Transformer; import
javax.xml.transform.TransformerFactory; import
javax.xml.transform.stream.StreamSource; import
javax.xml.transform.stream.StreamResult; import
javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.OutputKeys;
TransformerFactoryfactory= TransformerFactory.newInstance();
Transformertransformer= factory.newTransformer(xsl);
new StreamResult(System.out);
}
}
Output of the program:-
The following figure illustrates how the xslt transformer constructs the source tree from
source xml document and by using that with the help of xsl program how the result tree is
constructed.
Result tree is constructed base on the followingdefinitions given in xsl style sheet
<xsl:template match="/">
<html><head><title> XSL for Transforamtion </title>
<body><p>
<xsl:for-each select="Employee"> <xsl:value-of
select="child::Emp_Id"/>
<xsl:value-of select="child::Emp_Name"/>
<xsl:value-of select="child::Emp_E-mail"/>
</xsl:for-each>
</p></body></html>
</xsl:template>
XPATH
Is the syntax for specifying a collection of elements on other info contained within xml doc.
XPATH expression will be applied to parse the xml doc. which constructs a tree like
representation of xml doc. similar to DOM tree.
<xsl:template match="/"> which represents the XPath document root. An XPath expression
such as this represents one or more nodes within XPath parse tree is known as location
path.
Node test
The following are several axis names uses to search a particular element in the xml doc.
Predicate:
XPath uses some predicate which constructs the node test. Predicate can be either
child::<element name>
(Or)
Attribute::<value>
XMLuses a processing instruction which is a special xml rag that gas syntax similar to that
of xml declaration. The tag begins with <? and ends with ?>. Each processing instruction
begins with the name as the target of the processing instruction. The tag “xml-stylesheet”
is used to link the xml document with the css file.
Helloworld.xml
<? xml version=”1.0” encoding=”UTF-8” ?>
<? xml-stylesheet type=”text/html” href=”helloworld.css” ?>
<message> Hello World! </message>
Hellowworld.css
message {
display:block;
margin: 8pt; font-
weight=bold;
}
When xml doc. Helloworld.xml is executed, the xml doc is linked to the specified
“Helloworld.css” file and displays the output after applying css specifications.
What is JSP?
JSP Stands for "Java Server Pages". Using "JSP" we can use both, static HTML
with dynamically-generated HTML. Web pages created using CGI programs are
mostly static , dynamic part is limited to a few small locations. But using CGI and
servlet , you can generate entire page through one program. Using JSP, you can built
two parts separately.
Advantages of JSP:-
– If any error occurs while executing, the exception will occur which gives
the information for the servlet not for the JSP
OBJECT CLASS
Out JSP
writer
Request HttpServletRequest
Response HttpServletRespose
Session HttpSession
Application ServletContext
Config Sevlet
Config
www.Vidyarthiplus.com
Page Object
In servlets both the presentation and business logic are place it together where as in
jsp both are separated by defining by java beans.
Servlet is a java code where HTML code can be embedded whereas in jsp, it is a
kind of HTML where java code can be embedded by using special tags.
JSP allows creating and using custom tag libraries.
For example,
In this code, jsp elements that use java code are merged with HTML code.
Scoped Variables
Four different types of variable scopes within the JSP page can be used:
Page Scope: Objects stored in page scope can only be retrieved during the processing
of that page for a specific request.
Request Scope: Objects stored in request scope can be retrieved during the processing
of all pages taking part in the processing of a request
Session Scope: Object stored in session scope can be retrieved by any pages accessed
by a user during a single interactive session with the Web application
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Application Scope: Object stored in application scope is accessible from all pages
and for all users, until the Web application itself is unloaded
In this section, We will simply output "Hello JSP" in a web browser using Jsp expression.
JSP expressions insert values directly into the output. The syntax to include a JSP
expressions in the JSP file is:
In JSPpage, we can use both, static HTML with dynamically-generated HTML. In this
program, we produce output "hello Jsp" using this tag :
<html>
<head><title>Hello World JSP Page.</title></head>
<body>
<<%= "Hello JSP!" %>
</body>
</html>
Web Applications
• Servlets /JSP,
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
• Other resources:
• Browser: IE/Netscape/Chrome/FireFox
The following sectionexplains thesteps you must take to run sample JSP into
1. Preparation
2. Deploy
3. Run
1. Preparation
2. Deploy
1. In the test directory, create two directories named META-INF and WEB-INF. Now
you should have a directory structure that looks like this:
2. Create the XML descriptor: Here is the sample XML descriptor you can use to
deploy this example. Save this file as web.xml in the WEB-INF directory.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
<servlet-name>ExcelCalculatorJSP </servlet-name>
<display-name>ExcelCalculatorJSP</display-name>
<jsp-file>/ExcelCalculatorExample.jsp </jsp-file>
</servlet>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
3. Create a manifest file: Create a file called Manifest.mf (it can be an empty file) and
save it in the META-INF directory.
4. After you finished putting these files on the correct place, your directory structure
looks like this:
5. Now you need to add this new JSP to server.xml. Go to the conf directory and
open server.xml.
6. Add the following lines at the bottom of server.xml
3. Run
Basic JSP
Directives
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Declarations
Expressions
Standard Actions
Scriplets
Directives
The directives are used to specify the attributes of the JSP page. Also it can be used to import
java packages in to the jsp page. For example,
Where language=”java” tells tha the page is contains java code, the code
contentType=”text/html” specifies the MIME type, the code import =”java.util.*” used to
import all the classes of java‟s utility package into this page.
Scriplets: Consists of valid Java code snippets that are enclosed within <% and %> symbols.
The syntax to declare JSP scriptlets to include valid Java code is:
Scriplets can't generate HTML itself. Using "out" variable, it can generate HTML. This
variable does not need to be declared. It is already predefined for Scriplets, along
with some other variables. The "out" variable is of type "javax.servlet.jsp.JspWriter".
For example,
<HTML>
<BODY>
<%
java.util.Date date = new java.util.Date();
%>
Hello! The time is now
<%
out.println( String.valueOf( date ));
%>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
</BODY>
</HTML>
Expression:
Insert values directly into the output. The syntax to include a JSP expression in the JSP file is:
<%= expression%>.
%> Actions
The elements which are used to access the java bean in a jsp page is called jsp action elements.
JSP defines the following action elements:
Standard action
Tags Description
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<jsp:param> processed
Java Beans are reusable components. They are used to separate Business logic from the Presentation
logic. Internally, a bean is just an instance of a class.
Bean class = name of the java class that defines the bean.
An variant for this tag is the property attribute can be replaced by an “*”. What this does is that it
accepts all the form parameters and thus reduces the need for writing multiple setProperty tags.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
The only consideration is that the form parameter names should be the same as that of the bean
property names.
Here the property is the name of the property whose value is to be obtained from the bean.
</BODY>
</HTML>
JSTL
www.Vidyarthiplus.com
www.Vidyarthiplus.com
www.Vidyarthiplus.com
www.Vidyarthiplus.com
The goal of JSTL, is to help simplify Java Server Pages page authoring tasks. To
achieve this goal, JSTL has provided custom tags for many common JSP page authoring
tasks that require scripting statements to manipulate server side dynamic data.
The following table summarizes these functional areas along with the prefixes used in the
jsp pages.
Core tag
<c:set>
<c:remove>
<c:forEach>
<c:if>
<c:choose>
<c:when>
<c:set>
The <c:set> action provides a tag-based mechanism for creating and setting scoped
variables. For example,
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
<c:remove>
<c:forEach>
The <c:forEach> custom tag is used to fetch and display collections of data, typically in the
form of a list or sequence of rows in a table. This tag supports two different styles of
iteration:
The index of the iteration starts at the value of the begin attribute, is incremented by the
value of the step attribute, and halts iteration when it exceeds the value of the end
attribute. If the step attribute is omitted, the step size defaults to 1.
For example,
Output: 10 12 14 16 18 20
<c:if>:
<c:if> evaluates a single test expression and then processes its body content only
if that expression evaluates to true. If not, the tag's body content is ignored.
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
For example,
<c:choose>:
<c:choose> is provided for cases in which mutually exclusive tests are required
todetermine what content should be displayed.
<c:choose>
<c:when test="expression">
------------
</c:when>
-------------
<c:otherwise>
-------------
</c:otherwise>
</c:choose>
For example,
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
</c:choose>
<c:out>
The<c:out> tag evaluates the expression specified by its value attribute, then prints the
result. If the optionaldefault attribute is specified, this action will instead print its value
if the value attribute's expression evaluates either to null or an empty String.
This is one of the most important features of the JSTL and is a prominent feature of the JSP
2.0 specification.
The JSP 2.0 expression language helps to simplify the presentation layer by replacing hard-
to- maintain Java scripting elements in jsp page.
The syntax of expression language is very simple. EL expressions are invoked with this
syntax:
${expr}, where exprrepresents anany valid expression. For example,
${20 * 2}
For example,
<html> <body>
<form method=”post” action=”ElDemo.jsp”>
Enter user name: <input type=”text” name=”t1” />
<input type=”submit” value=”submit” />
</form>
</body></html>
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
WEB TECHNOLOGY
Step 2: Create a jsp file to obtain user name from the above html file using EL
EL Reserved Words:
Following words are EL keywords and hence must not be used as identifiers:
EL Operators
Category Operators
Arithmetic +, -, *, / ordiv, % or mod
Relational == or eq, != or ne, < or lt, > or gt, <= orle, >=
or ge
Logical && or and, || or or, ! ornot
Many web applications are based on the Model-View-Controller (MVC) architecture pattern.
That is, web apps contains three parts: 1) business logic 2) presentation and 3) request
processing
The key motivation behind the MVC approach is the desire to separate the code that creates
and manipulates the data (i.e business logic) from the code that presents the data (i.e
presentation) and the code that process the request (i.e controller)
Business logic means the codeapplied for manipulation of application data and
presentation refers the code written for look and feel of the web page such as background
color, font style, placing of form controls and so on. Controller means that process the
request message.
DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
According to MVC, the Model corresponds to business logic, the View corresponds to
presentation and the Controller corresponds to request processing
Java servlet program is the Controller component that receives the request from the browser.
Java bean class is the Modelcomponent that processes the business logic which can use the
data source for that.
Jsp is the View component that presents theresult of the business logic to the browser with
the help of controller. The following program also illustrates that.
In this architecture, JSP is used for creating the view for the application. A centralized
Servlet is used to handle the entire request for the application. The Servlet works as the
controller for the application. It then uses the Java beans for processing the business
logic and getting the data
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
(Model) from the database. Finally it uses the JSP to render the view which is displayed to
the user.
- MVC allows the developer to keep the separation between business logic,
presentation and request processing. Due to this separation, any changes to the
presentation can be made easy without disturbing business logic.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
UNIT V
Web Services: JAX-RPC-Concepts-Writing a Java Web Service-Writing a Java
Web Service Client-Describing Web Services: WSDL- Representing Data Types:
XML Schema-communicating Object Data: SOAP Related Technologies-
Software Installation-Storing Java Objects as Files-Databases and Java
Servlets
Web Services
Web services are open standard based Web applications that interact with
other web applications for the purpose of exchanging data.
Body of web services request and response will be SOAP message which
defines a protocol for message exchange between applications.
1. Currency Converter
2. Temperature conversion
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
technologies:
SOAP
WDSL
XML Schema
RPC JAX-RPC
It stands for Java API for XML-based RPC. JAX-RPC is a technology for
building web services and clients that use remote procedure calls (RPC) and XML.
Often used in a distributed client-server model, an RPC mechanism enables
clients to execute procedures on other systems.
With JAX-RPC, clients and web services have a big advantage: the platform
independence of the Java programming language. In addition, JAX-RPC is
not restrictive: a JAX-RPC client can access a web service that is not
running on the Java platform, and vice versa. This flexibility is possible
because JAX-RPC uses technologies defined by the World Wide Web
Consortium (W3C) such as:
These are the basic steps for creating the web service and client:
1. Create an interface
2. Code the implementation class.
3. Use wscompile to generate wsdl doc.
4. Create deployment descriptor file
5. Package the files into a WAR file.
6. Deploy the WAR file.
7. Create a client file to access the web service
8. Use wscompile to generate and compile the web service artifacts needed to
connect to the service.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
package myCurCon;
public interface CurCon extends java.rmi.Remote
{
public ExchangeValues fromDollars(double dollars) throws
java.rmi.RemoteException; public ExchangeValues fromEuros(double dollars) throws
java.rmi.RemoteException; public ExchangeValues fromYens(double dollars) throws
java.rmi.RemoteException;
}
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
- Save this file as config.xml and use the following command to create
wsdl doc.
wscompile –define – d WEB-INF –classpath WEB-INF/classes – model WEB-INF/model.xml.gz
config.xml
-d specifies the directory to receive the generated wsdl doc. which will be
named as Historic Currencyconverter.wsdl
urlPattern="/Currency" />
</webServices>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
The tag <endpoint> gives the information to web server including name of
the service end point interface, implementation file model generated by
wscompile etc.
Step 6: Package and deploying the web service created
Create WAR(Web Archive) file. Add the deployment descriptor and service
files to the WAR file. The following command is used:
jar cf converter-temp.war WEN-INF
Deploy the war file using the following command
wsdeploy –o converter.war converter-
temp.war Step 7: Start tomcat server
Step 8: Browse to http://localhost:8080/Converter/Currency to see the status
of the currency converter web service. The output will be:
packageName="myCurConClient" />
</configuration
Step 2: Use wscompile to load wsdl from the url specified in the location
attribute of config.xml. Use the following command for that
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
This instructs to generate a class file from the wsdl and keep the java source
file in src folder.
Step 3: Create java client program for accessing the web services as shown below
package mycurConClient;
public class CurConBean
{
private double value=1.0; private
String Currency="dollars";
public void setValue(double value)
{
this.value=value;
return;
}
public void setCurrency(String currency)
{
this.currency=currency;
return;
}
public ExchangeValues getExValues()
{
ExchangeValues ev=null;
CurCon=(new HistoricCurrencyConverter_impl().getCurConPort());
try
{
if(currecny.equals("euros")
{
ev=curcon.fromEuros(value);
}
else if(currency.equals("yens")
{
ev=curcon.fromYens(value);
}
}catch(Exception e){}
return ev;
}
Step 5: Create a jsp for using this bean class to perform a currency conversion
class and display the result in a HTML file
<html>
<jsp:useBean id="client" class="myCurConClient.CurConBean" />
<body>
<%
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
String value=request.getPArameter(val);
%>
This invokes the web service from the server and converts the euros value
500.30 to equivalent dollars and yens value and displays the result.
SOAP
WSDL
WSDL is often used in combination with SOAP and XML Schema to provide
web services over the Internet. A client program connecting to a web service
can read the WSDL to determine what functions are available on the server.
Then the client can then use SOAP to actually call one of the functions
listed in the WSDL.
<definitions>
<types>
definition of types........
</types>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<message>
definition of a message....
</message>
<portType>
<operation>
definition of a operation.......
</operation>
</portType>
<binding>
definition of a binding....
</binding>
<service>
definition of a service....
</service>
</definitions>
A WSDL document can also contain other elements, like extension elements
and a service element that makes it possible to group together the definitions
of several web services in one single WSDL document.
Element Defines
<types> The data types used by the web service
<message> The messages used by the web service
<portType> The operations performed by the web service
<binding> The communication protocols used by the web service
A WSDL document can also contain other elements, like extension elements,
and a service element that makes it possible to group together the definitions
of several web services in one single WSDL document.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<types>
<schema>
<import namespace="uri" location="uri"/>
<complexType name=” “>
<sequence>
<element name=” “ type=” “ />
:
:
</sequence>
</complexType>
</schema>
</types>
The types element defines data type definitions that are relevant for the
exchanged messages. The content of types is normally XML schema markup.
The data type can be either complex type or simple type.
The sequence element is a collection of <element> tags. Each element tag
specifies name of the operation (service or method) provided by the web
service and its data type of the return value.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
</binding>
</definitions>
A service groups a set of related ports together. This provides a name for
overall web service. Each port associates a binding with an internet address.
This address is specified by including a soap: address element in the
content of the port as shown.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
use="encoded"/>
</input>
<output>
<soap:body encodingStyle="uri" namespace="uri"
use="encoded"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address location="uri">
</port>
</service>
</definitions>
Definition : HelloService
Type : Using built-in data types and they are defined in XMLSchema.
Message :
1. sayHelloRequest : firstName parameter
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Here is the example piece of code from last session which uses definition element.
<definitions>
A Web service needs to define its inputs and outputs and how they are
mapped into and out of services. WSDL <types> element takes care of
defining the data
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
types that are used by the web service. In other words, the types element
describes all the data types used between the client and server. The types
element in WSDL doc is optional.
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse"> <part
name="greeting" type="xsd:string"/>
</message>
Here, two message elements are defined. The first represents a request message
SayHelloRequest, and the second represents a response message SayHelloResponse.
Each of these messages contains a single part element. For the request, the
part specifies the function parameters; in this case, we specify a single
firstName parameter. For the response, the part specifies the function return
values; in this case, we specify a single greeting return value.
<portType> can combine one request and one response message into a
single request/response operation. This is most commonly used in SOAP
services. A portType can define multiple operations.
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
soap:binding
This element indicates that the binding will be made available via SOAP.
The style attribute indicates the overall style of the SOAP message
format. A style value of rpc specifies an RPC format. The transport
attribute indicates the transport of the SOAP messages.
soap:operation
This element indicates the binding of a specific operation to a specific
SOAP implementation. The soapAction attribute specifies that the
SOAPAction HTTP header be used for identifying the service.
soap:body
This element enables you to specify the details of the input and output
messages. In the case of HelloWorld, the body element specifies the SOAP
encoding style and the namespace URN associated with the specified
service.
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
transport="uri"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body encodingStyle="uri" namespace="uri" use="encoded"/>
</input>
<output>
<soap:body encodingStyle="uri" namespace="uri" use="encoded"/>
</output>
</operation>
</binding>
The <service> element defines the ports supported by the Web service. For
each of the supported protocols, there is one port element. The service
element is a collection of ports.
Web service clients can learn from the service element where to access the
service, through which port to access the Web service, and how the
communication messages are defined.
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://www.examples.com/SayHello/">
</port>
</service>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
XML Schema
An XML Schema:
One of the greatest strength of XML Schemas is the support for data types.
Using XML schema it is easier to describe allowable document content; it
is easier to validate the correctness of data; it is easier to convert data
between different data types.
XML Schema has a lot of built-in data types. The most common types are:
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Step 1: Write a xsd file in which the desired structure of the XML document
is defined and named it as StudentSchema.xsd.
<?xml version=”1.0”?>
<xs:schema xmlns:xs=” http://www.w3.org/2001/XMLSchma”>
<xs:element name=”student” >
<xs:complexType>
<xs:sequence>
<xs:element name=”name” value=”xs:string”
/>
<xs:element name=”regno” value=”xs:string” />
<xs:element name=”dept” value=”xs:string” />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The xs qualifier used to identify the schema elements and its types. The
xs:schema is the root element. It takes the attributes xmlns:xs which has
the value, “http://www.w3.org/2001/XMLSchema. This declaration
indicates that the document follows the rule of XMLSchema defined by
W3 in year 2001.
The xs:element is used to define the xml element. The Student element is
complexType which has three child elements:name, regno and dept. All
these elements are of simple type string.
Step 2: Write a XML document and reference the xsd file. Named
it as myXML.xml
<?xml version=”1.0”?>
<student xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”StudentSchema.xsd”>
<name> Raj </name>
<regno>3212654556</regno>
<dept>CSE</dept>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
</student>
Various xml validation tools are available which can be used to validate xml
and its schema document.
Advantages
Disadvantages
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
A DTD defines the document structure with a list of legal elements and
attributes.
PCDATA means parsed character data which is the text found between the
start tag and the end tag of an XML element.
Step 2: Write the XML document and reference the DTD file in it. Name
it as myXML.xml
<?xml version=”1.0”?>
<!DOCTYPE student SYSTEM student.dtd>
<student>
<name> Raj </name>
<regno>3212654556</regno>
<dept>CSE</dept>
</student>
!DOCTYPE student defines that the root element of this document is student
and links the myXML.xml file with the student.dtd file.
SOAP
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
Blocks
HTTP binding
// used to directs the message
Envelop
// helps the server to identify the message as SOAP
Header
// Optional. It adds features to SOAP message such as authentication, message
route etc.
Body
// contain actual message
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<soap:Body>
... ... ...
<soap:Fault>
... ... ...
</soap:Fault>
</soap:Body>
</soap:Envelope>
A SOAP Example
A SOAP request:
POST /InStock
HTTP/1.1 Host:
www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: n bytes
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="uri" soap:encodingStyle="uri">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: n bytes
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="uri" soap:encodingStyle="uri">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
Related technologies
SCE DEPT OF
CSE
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
SCE DEPT OF
CSE
www.Vidyarthiplus.com
UNIT – I
1. What is the difference between node and host?
A node is any addressable device connected to a network whereas the host is a
more specific descriptor that refers to a networked general-purpose computer rather than a
single purpose device (such as a printer).
3. Define protocol.
A protocol is a formal set of rules that must be followed in order to communicate.
5. Define encapsulation.
Placing the data inside a package of headers is known as encapsulation.
6. Define port.
A port is a logical channel to an application running on a host. ie., The
applications running on the host machines are uniquely identified by port numbers.
20. What are the sequences of steps for each HTTP request from a client to the server?
1. Making the connection
2. Making a request
3. The response
4. Closing the connection
UNIT II
platform, whereas Netscape’ s Web servers run on all major platforms, including Windows
NT platform, OS/2 and UNIX.
27. What are ISAPI (Internet Server API) and NSAPI (Netscape Server API)
ISAPI (Internet Server API): An API for Microsoft’s IIS (Internet Information
Server) Web server. ISAPI enables programmers to develop Web-based applications that
run much faster than conventional CGI programs because they’re more tightly integrated
with the Web server. In addition to IIS, several Web servers from companies other than
Microsoft support ISAPI.
NSAPI -Netscape Server API: An API for Netscape’s Web servers. NSAPI
enables programmers to create Web-based applications that are more sophisticated and run
much faster than applications based on CGI scripts.
28. What is API -Application Program Interface?
A set of routines, protocols, and tools for building software applications. A good
API makes it easier to develop a program by providing all the building blocks. A
programmer puts the blocks together.
Most operating environments, such as MS- Windows, provide an API so that
programmers can write applications consistent with the operating environment. Although
APIs are designed for programmers, they are ultimately good for users because they
guarantee that all programs using a common API will have similar interfaces. This makes it
easier for users to learn new programs.
there was no prior connection and each request can yield only a single document. This
is known as Stateless Connection.
66. Write down the Socket object methods to get information about a socket.
1. getInetAddress ()- displays which remote host the Socket is connected to
2. getPort () -displays which port the Socket is connected to on the remote host.
3. getLoca1Port ()- to find the port number for the local end of a connection
4. getLocalAddress () -tells you which network interface a socket is bound to.
UNIT IV
71. What are the style precedence rules when using multiple approaches?
Inline styles override both linked style sheets and style information stored in the
document head with <STYLE> tag.
Styles defined in the document head override linked style sheets.
Linked style sheets override browser defaults.
72. Give the syntax to specify a characteristic in linked style sheet.
{Characteristic: value}
Multiple characteristic/value pairs should be separated by semicolons.
77. What are the XML rules for distinguishing between the content of a document and the
XML markup element?
1. The start of XML markup elements is identified by either the less than symbol (<)
or the ampersand (&) character
2. Three other characters, the greater than symbol (>), the apostrophe or single
quote (‘) and the double quotation marks (“) are used by XML for markup.
3. To use these special characters as content within your document, you must use the
corresponding general XML entity.
85. Write down the various attributes for the page directives in JSP.
The page directive defines information that will be globally available for that
Java Server Page,
1. language
2. extends
3. import
4. session
5. buffer
6. contenttype
UNIT- 5
ON LINE APPLICATION
91. What is meant by Plug-in?
A hardware or software module that adds a specific feature or service to a larger
system. The idea is that the new component simply plugs in to the existing system. For
example, there are number of plug-ins for the Netscape Navigator browser that enable it to
display different types of audio or video messages. Navigator plug-ins are based on MIME
file types.
PART B
14. List the XML syntax rules in detail and Explain how a XML document can be
displayed on a browser
15. Consider the database table with the following structure Student (studentname,
register_number, Grade_obtained, Age) Write a JSP to display all the details of the
Student
16. Explain the model view controller architecture pattern in detail
17. What does JSP scripting component includes? Explain with program
18. Explain how XML is processed with the help of SAX
19. Write a DTD for the following schema (emp_id, emp_name (firstname, lastname),
dob(dd, mm, yyyy). address(city, state)).
20. Explain the SOAP elements and JAX RPC in detail
21. Explain in detail the XML schema, built in and user defined data type in detail
22. Explain the JDBC database connectivity in detail
23. Explain in detail the XML schema,built in and user defined data types in detail
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
www.Vidyarthiplus.com
www.Vidyarthiplus.com
IT2353 WEB TECHNOLOGY
www.Vidyarthiplus.com