WebTechnology - Puducherry University Unit 2
WebTechnology - Puducherry University Unit 2
UNIT-II
Search and Design: Worldwide search-web searching overview-working of search
engines-search engine promotion-optimization-Search interface. Web protocols-HTTP
DNS- Web Servers-components-software-web hosting. Browsers-HTML and scripting
languages-cookies- Multimedia in web design.
Gathering Pages
Every day the web is growing by leaps and bounds. The true size of the web is
unknown, and it will undoubtedly increase even as you read this sentence.
At any given moment numerous documents are added and others are
removed.
Gathering all the pages and keeping things up-to-date is certainly a significant
chore.
Users always want to know which search engine covers the most of the web,
but the truth is that today even the largest search engines index maybe only
a third of the documents online. Some index only a few percent.
In the case of local site search engines, the index might also not cover the
entire site nor be updated often.
Most search engines use programs called spiders, robots, or gathers to
collect pages of the web for indexing.
Spiders start their gathering process with a certain number of starting point
URLs and work from there by following links.
For example, if a spider were visiting the URL://www.democommpany.com, it
might see links emanating from this page and then decide to follow them.
Indexing Pages
The next step search engines take is attempting to determine what a page is
about. This is usually called indexing.
Tricky Business
The tricks employed by search engine specialists are numerous and change
all the time. Many ideas are simple add-ons to normal web design techniques.
Search engine promoters might say, “why not put alt attributes on these
images to improve things. Imagine, for instance, having the following all over
your page:
<img src=”pixel.gif” alt=”robot butler robot butler robot butler” />
Spamming pages with invisible text, small text, and multiple images, or just
loading the <meta> or <title>tags, are not the most sophisticated
tricks, but they often work.
Other tricks include the infamous “bait and switch”, where a special search
engine page is created and then posted to a search engine.
Once the ranking is high, the bait page is replaced with a real page built for
users. A more complicated version of this could be dubbed “feeding the dogs”.
Distinguishing search engines from regular users isn’t terribly difficult, since
the engines identify themselves and come from consistent IP addresses.
In reality, “feeding the dogs” is just a modified form of browser detection.
The problem with all the search engine promotion ideas is that they tempt the
designer to stop building pages for users and start building them for search
engines.
“Do not design pages solely to attract search engines, as, ultimately,
pages are for people”.
Accessing Search
Should consider how users will access the search facility. Some sites create a
special button labeled “search” that, when selected, takes the user to a
special search page. Other sites utilize a search field within all pages.
While putting the search directly on the page eliminates one click for the user,
a search field within a content page must be very basic.
There still may be a need for a special search page if more complex queries
are to be formed.
It really isn’t possible to put advanced search mechanisms within every page,
as it tends to make the search facility too prominent and takes away from the
page’s primary purpose of delivering content. Search should be easily found
from every page in a site.
“When search is available in a site, include a search button or field on
all pages”.
SEARCH VS Search:
GO
Robot Exclusion
It is not always a good idea to have a robot index your entire site. First, some
pages such as programs in your cgi-bin directory don’t need to be indexed.
Second, many pages may be transitory, and having them indexed may result in
users seeing 404 errors if they enter from a search engine.
Finally, you may just not want people to enter on every single page-
particularly those pages deep within a site.
So-called “deep linking” can be confusing for users entering from public search
engines.
The basic idea of most spiders is to read pages and follow pages as fast as
they can. Most people are not malicious in spidering, but it does happen
inadvertently when a spider keeps reindexing the same dynamically generated
page.
Robots.txt
III Year/VI Sem 9
IT-T62 Web Technology UNIT II
To deal with limiting robot access, the RobotExclusion protocol was adopted.
The basic idea is to use a special file called robots.txt that should be found in
the root directory of a web site.
For example, if a spider was indexing http://www.democompany.com, it would
first look for a file at http://www.democompany.com/robots.txt. If it finds a file,
it would analyze the file first before proceeding to index the site.
The basic format of the robots.txt file is a listing of the particular spider or user
agent. For example,
User-agent: *
Disallow: /cgi-bin/
Disallow: /temp/
Disallow: /archive/
In this case, we have denied access for all robots to the cgi-bin directory, the
temp directory, and an archive directory- possibly where we found move files
that are very old but still need to be online. Consider this file:
User-agent: *
Disallow: /cgi-bin/
Disallow: /images/
Disallow: /subscribers-only/
Disallow: /resellers.html
In this file, a special subscribers-only and resellers file has been disallowed for
indexing.
A malicious spider will, of course, simply ignore this file, and you may be forced
to set your server to block particular IP addresses or user agents if someone
has decided to attack your sites.
6. WEB PROTOCOLS
HTTP stands for Hypertext Transfer Protocol. It is the standard protocol for transferring
web pages (and their content) across the Internet.
• HTTP - Hyper Text Transfer Protocol
o HTTP takes care of the communication between a web server and a web
browser.
o HTTP is used for sending requests from a web client (a browser) to a web
server, returning web content (web pages) from the server back to the
client.
o HTTPS - Secure HTTP
o HTTPS takes care of secure communication between a web server and a
web browser.
o HTTPS typically handles credit card transactions and other sensitive data.
o The GET and POST are two popular methods used by the HTTP protocol.
o It is also called a Stateless Protocol because this protocol is not able to
maintain the previous information.
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:
GET for queries that can be safely repeated
POST for operations that may have side effects (e.g. ordering a book from an
on-line store).
The GET Method
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]
III Year/VI Sem 11
IT-T62 Web Technology UNIT II
Cannot be unused for uploading files or other operations that require large
amounts of data to be sent to the server.
7. WEB SERVERS
Web server is just a computer running a piece of software that fulfills HTTP
requests made by browsers.
In the simplest sense, a web server is just a file server- and a slow one at
times. However, a web server isn’t just a file server, because it can also run
programs and deliver results.
Web servers could also be considered application servers- if, occasionally,
simple or slow ones.
Apache(http: //www.apache.org/)
Apache
It is an excellent server because of its two important
features: Reliability and Efficiency.
It is more popular because it is an open source software.
Apache web server is best suitable for UNIX system but it can
also be used on Window box.
The apache web server can be configured as per the
requirements using the file httpd.conf.
This file is present in the apache software package.
IIS
The internet information services or internet information
server is a kind of web server provided by Microsoft.
This server is most popular on windows platform.
For IIS server, the behavior is controlled by modifying the
window based management programs called IIS snap in.
We can access IIS snap in through the control panel-
>Administrator Tools.
4D WebStar( http://www.starnine.com/)
Initially a popular web server for the Macintosh originally based on MacHTTPD,
WebStar integrates well with the traditional macintosh interface.
The server has solid security features and supports native macintosh
technologies, as well as UNIX-style CGI programs, PHP, a java virtual machine for
server side java, and extended SSI.
Apache on OSX tends to be a better choice for larger Macintosh-powered sites.
III Year/VI Sem 16
IT-T62 Web Technology UNIT II
Zeus(http://www.zeus.com)
Zeus as a contender for the fastest web server. This server is becoming popular
with extremely high volume web sites.
The zeus server does not lack development capabilities, as it provides not only
java compatibility but supports both IIS’s ISAPI interface and the NSAPI interface
introduced on Netscape Enterprise servers.
8. Web hosting
As websites become more critical to the information on frastructure of the
companies, there is a growing need to provide high-quality, high-availability
solutions.
For example a business selling something only online can’t afford to have its site
go down at all. The serving of a site to an e-business is as critical as power and
telephone services would be to a traditional business.
This trend might be termed the “utilization” of the web, as some may consider
the health and delivery of their web site as important as other utilization of the
web as some may consider the health and health and delivery of their web sites
as important as other efficient and reliable manner, firms quickly discover that it
is in fact quite expensive for companies for develop in house the talents and
facilities to run a mission-critical website.
Therefore, many firms have decided to outsource their web facilities. Web server
outsourcing comes in many favours, but many of the differences revolve around
two factors. The first differentiating factor is whether your site is sharing a
machine with other sites the second is whether or not the machine being used
in owned and managed by you or the outsource vendor. Each type of service will
be discussed in term with special focus on their pros and cons.
Shared hosting
The most basic form of hosting, shared hosting ranges from free web space
added to other services or in exchange for advertisement placement to high end
application service providers.
At the low end many internet service providers will provide a directory on one of
their web servers with a few megabytes of diskspace and possibly access to a
few shared tools that can be used on your website such as simple form handling
scripts counters or message boards.
III Year/VI Sem 17
IT-T62 Web Technology UNIT II
Usually the URL for a site like this is of service lacks any customization like your
domain name and it may impose limits on traffic delivered or programming tools
that can be used.
The upside of these types of services is that they are often free or may be
included in the cost of your Internet connection.
There are also many vendors who will provide free web services in exchange for
personal information for marketing purpose, or if you agree to show the banner
advertisement, they book on your site.
While these services are appealing to home users or those looking to put up on
site for fun, most will prefer other terms of shared hosting.
Dedicated hosting
Because of the downside of sharing a server with others most notably security
and control many people opt to use a dedicated server.
Dedicated servers are advantageous because you can customize your server
with whatever tools or programs you like, and you are not affected by other sites
as much. However, the trade-off is cost.
Dedicated server tend to be more expensive.
There are two forms of dedicated server hosting. The first is where the outsource
vendor owns and maintains the equipment. This may be called fully managed or
dedicated hosting. The other is where you own and may ever be responsible for
maintaining your server.
9. HTML
HTML Tags
HTML tags are keywords (tag names) surrounded by angle brackets like
<html>
HTML tags normally come in pairs like <b> and </b>
The first tag in a pair is the start tag, the second tag is the end tag
Start and end tags are also called opening tags and closing tags
<tagname> content</tagname>
HTML Elements
"HTML tags" and "HTML elements" are often used to describe the same thing.
But strictly speaking, an HTML element is everything between the start tag and the end
tag, including the tags:
HTML Element:
<p>This is a paragraph.</p>
Web Browsers
The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox,
Safari) is to read HTML documents and display them as web pages. The browser does
not display the HTML tags, but uses the tags to interpret the content of the page:
HTML Headings
HTML Paragraphs
HTML documents are defined by HTML elements. An HTML element is everything from the
start tag to the end tag:
Start tag * Element content End tag *
<p> This is a paragraph </p>
<a This is a link </a>
href="default.htm">
<br>
* The start tag is often called the opening tag. The end tag is often called the closing
tag.
III Year/VI Sem 20
IT-T62 Web Technology UNIT II
HTML Element Syntax
The element content is everything between the start and the end tag
HTML Attributes
HTML Attributes
Attribute Example
HTML links are defined with the <a> tag. The link address is specified in the href
attribute:
Example
<a href="http://www.w3schools.com">This is a link</a>
Below is a list of some attributes that can be used on any HTML element:
Attribute Description
Class Specifies one or more classnames for an element (refers to a class in a
style sheet)
Id Specifies a unique id for an element
Style Specifies an inline CSS style for an element
Title Specifies extra information about an element (displayed as a tool tip)
HTML Comments
Comments can be inserted into the HTML code to make it more readable and
understandable. Comments are ignored by the browser and are not displayed.
Use the <br> tag if you want a line break (a new line) without starting a new
paragraph:
Example
<p>This is<br>a para<br>graph with line breaks</p>
HTML uses tags like <b> and <i> for formatting output, like bold or italic text.
These HTML tags are called formatting tags (look at the bottom of this page for a
complete reference).
HTML Links
Links are found in nearly all Web pages. Links allow users to click their way from page
to page.
• Hyperlink
– References other sources such as XHTML documents and images
– Both text and images can act as hyperlinks
– Created using the a (anchor) element
• Attribute href
– Specifies the location of a linked resource
• Link to e-mail addresses using mailto: URL
• <strong> tag
– Bold
Example:
<a href = "mailto:[email protected]">
[email protected]
</a>
Example: 1
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Internet and WWW How to Program - Links</title>
</head>
<body>
<h1>Here are my favorite sites</h1>
<p><strong>Click a name to go to that page.</strong></p>
<!-- Create four text hyperlinks -->
<p><a href = "http://www.deitel.com">Deitel</a></p>
<p><a href = "http://www.prenhall.com">Prentice Hall</a></p>
<p><a href = "http://www.yahoo.com">Yahoo!</a></p>
<p><a href = "http://www.usatoday.com">USA Today</a></p>
Images
• Three most popular formats
– Graphics Interchange Format (GIF)
– Joint Photographic Experts Group (JPEG)
– Portable Network Graphics (PNG)
– img element
• src and alt attribute
src - Specifies the location of the image file.
alt - Display the when it is not possible to display the image
• width and height
• Pixels (“picture elements”)
• Empty elements
– Terminated by character / inside the closing right angle bracket (>), or by
explicitly including the end tag
• br element
– Line break
Example:
<img src = "jhtp.jpg" height = "238" width = "183"
alt = "Java How to Program book cover" />
Example:
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Internet and WWW How to Program - Welcome</title>
</head>
<body>
<p>
<img src = "xmlhtp.jpg" height = "238" width = "183"
III Year/VI Sem 23
IT-T62 Web Technology UNIT II
alt = "XML How to Program book cover" />
<img src = "jhtp.jpg" height = "238" width = "183"
alt = "Java How to Program book cover" />
</p>
</body>
</html>
Unordered Lists
• Unordered list element ul (<ul>)
– Creates a list in which each item begins with a bullet symbol (called a
disc)
– li (list item) using <li>
• Entry in an unordered list
Syntax:
<ul> using bullet name
<li>data</li>
<li>data</li>
</ul>
Example:
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
III Year/VI Sem 25
IT-T62 Web Technology UNIT II
-->
<!-- Unordered list containing hyperlinks -->
Example:
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
</li>
<li>Links</li>
<li>Keeping in touch with old friends</li>
<li>It is the technology of the future!</li>
</body>
</html>
HTML Tables
Basic HTML Tables
• Organize data into rows and columns
• Table Element
– Attribute border
• Specifies the table’s border width in pixels
– Attribute summary
• Describes the table’s contents
– Attribute caption
<tr>
<td>Banana</td>
<td>$1.00</td>
</tr>
<tr>
<td>Pineapple</td>
<td>$2.00</td>
</tr>
</tbody>
</table>
</body>
</html>
Nested table:
Nested table means with in the table.
Example:
<html>
<head>
<title>Nested table</title></head>
<body>
<table border=”1”>
<caption align=”top”>
<b>Engg college</b>
</caption>
<tr>
<td>first year</td>
<td>second year</td>
</tr>
<tr>
<td>third year</td>
<td>
<table border=”1”>
<caption align=”top”>
<b>DEPT</b>
</caption>
<tr>
<td>IT</td>
<td>CSE</td>
</tr>
<tr>
<td>ECE</td>
<td>MECH</td>
</tr>
III Year/VI Sem 31
IT-T62 Web Technology UNIT II
</table>
final year</td>
</tr>
</table>
<h1> This is Nested table</h1>
</body>
</html>
<frameset rows="*,170">
<frame name="bottom" src="lisy.html"/>
<frame name="top" src="padd.html"/>
</frameset>
III Year/VI Sem 34
IT-T62 Web Technology UNIT II
</frameset>
</html>
HTML Forms
Form components:
Label
Text
Textarea
Button
Radio button
Check box
Menus
• Element form
– Attribute method
• Specifies how the form’s data is sent to Web server
• Element Label
– It is used to write the text.
Syntax:
<label> input string</label>
Example: <html>
<head>
<title>form</title>
</head>
<body>
<form>
<label>this is web technology</label>
</form>
</body>
</html>
• Element Text:
– It is typically required to place one line text.
Syntax:
<input type=”text” size =”20” value=””>
</input type>
Example:
<html>
<head>
<title>form</title>
</head>
<body>
<form>
<input type=”text” size =”20” value=””>
</input type>
</form>
</body>
</html>
• Element checkbox
– Enable users to select from a set of options
Syntax:
<input type=”check box” name=”option1” value=”name of the
checkbox”>
</input type>
III Year/VI Sem 38
IT-T62 Web Technology UNIT II
Example:
<html>
<head>
<title>checkboxes</title></head>
<body>
<form name=”checkbox”>
<div align=”center”><br>
<b>Select the fruits name</b></br>
<input type=”checkbox” name=”option1” value=”apple”>Apple</input
type>
<input type=”checkbox” name=”option2”
value=”orange”>orange</input type>
</div>
</form>
</body>
</html>
•Element Button
– Button are two types one is submit and another one is reset.
– Using two methods get and post.
Syntax:
<input type=”submit” value=”send></input type>
<input type=”reset” value=”clear”></input type>
Example:
<html>
<head>
<title>checkboxes</title></head>
<body>
<form name=”myfrom” action="www.google.com"
method="post">
<input type = "submit" value ="Submit " />
<input type = "reset" value ="Clear " />
</form>
</body>
</html>
• Element Menu
– Adds items to the drop-down list
– Attribute selected
• Specifies which item initially is displayed as the selected item
Syntax:
<select name=”menu name”>
<option value=”name of item”></option value>
</select>
Example:
<html>
<head>
<title>checkboxes</title></head>
<body>
<form name=”checkbox”>
<div align=”center”><br>
<b>Select the fruits name</b></br>
<select name=”Fruits”>
<option value=”Apple”>Apple</option>
<option value=”Mango”>Mango</option>
<option value=”Orange”>Orange</option>
</select>
</div>
</form>
</body>
</html>
Example:
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<body>
<h1>Feedback Form</h1>
<p><label>Name:
<input name = "name" type = "text" size = "25" />
</label></p>
III Year/VI Sem 42
IT-T62 Web Technology UNIT II
<p>
<strong>Things you liked:</strong><br />
<label>Site design
<input name = "thingsliked" type = "checkbox"
value = "Design" /></label>
<label>Links
<input name = "thingsliked" type = "checkbox"
value = "Links" /></label>
<label>Ease of use
<input name = "thingsliked" type = "checkbox"
value = "Ease" /></label>
<label>Images
<input name = "thingsliked" type = "checkbox"
value = "Images" /></label>
<label>Source code
<input name = "thingsliked" type = "checkbox"
value = "Code" /></label>
</p>
<p>
<input type = "submit" value =
"Submit Your Entries" />
<input type = "reset" value =
"Clear Your Entries" />
</p>
</form>
CSS was introduced together with HTML 4, to provide a better way to style HTML
elements.
Inline Styles
An inline style can be used if a unique style is to be applied to one single occurrence of
an element.
<p style="color:blue;margin-left:20px;">This is a paragraph.</p>
III Year/VI Sem 44
IT-T62 Web Technology UNIT II
The HTML <style> Element
The <style> tag is used to define style information for an HTML document.
Inside the <style> element you specify how HTML elements should render in a
browser:
<head>
<style type="text/css">
body {background-color:yellow}
p {color:blue}
</style>
</head>
<body style="background-color:yellow;">
<h2 style="background-color:red;">This is a heading</h2>
<p style="background-color:green;">This is a paragraph.</p>
</body>
</html>
The font-family, color, and font-size properties defines the font, color, and size of the
text in an element:
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="font-family:verdana;">A heading</h1>
<p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p>
</body>
</html>
The font-family, color, and font-size properties make the old <font> tag obsolete.
An internal style sheet can be used if one single document has a unique style. Internal
styles are defined in the <head> section of an HTML page, by using the <style> tag,
like this:
<head>
<style type="text/css">
body {background-color:yellow;}
p {color:blue;}
</style>
</head>
External Style Sheet
An external style sheet is ideal when the style is applied to many pages. With an
external style sheet, you can change the look of an entire Web site by changing one
file. Each page must link to the style sheet using the <link> tag. The <link> tag goes
inside the <head> section:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
HTML Layouts
Web page layout is very important to make your website look good.
</div>
</body>
</html>
<tr>
<td style="background-color:#FFD700;width:100px;text-align:top;">
<b>Menu</b><br>
HTML<br>
CSS<br>
JavaScript
</td>
<td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">
Content goes here</td>
III Year/VI Sem 47
IT-T62 Web Technology UNIT II
</tr>
<tr>
<td colspan="2" style="background-color:#FFA500;text-align:center;">
Copyright © W3Schools.com</td>
</tr>
</table>
</body>
</html>
Menu
HTML
Content goes here
CSS
JavaScript
Copyright © W3Schools.com
Explanation:
scheme - defines the type of Internet service. The most common type is http
host - defines the domain host (the default host for http is www)
:port - defines the port number at the host (the default port number for http
is 80)
path - defines a path at the server (If omitted, the document must be stored at
the root directory of the web site)
III Year/VI Sem 48
IT-T62 Web Technology UNIT II
filename - defines the name of a document/resource
9.Scripting:
A script consists of a set of instructions that are executed under certain
conditions.
Web scripting uses small programs that are executed based on user
interaction with a web page.
Scripting is widely used as part of web development.
Scripting allows you to turn a simple, static HTML page into a more dynamic
page.
Web scripts can run in one of two places: the client side, also called the front-
end, and the server side, also called the back-end.
The client refers to the web browser used to view a web page.
The server refers to the computer server that hosts the website.
Client side scripting and server side scripting
Client-side scripting
A client is a party that requests pages from the server and displays them to the
end user.
Client-side scripting generally refers to the class of computer programs on
the web that are executed client-side, by the user's web browser.
This type of computer programming is an important part of the Dynamic
HTML (DHTML) concept, enabling web pages to be scripted;
Client-side scripts are often embedded within an HTML or XHTML document
(hence known as an "embedded script"), but they may also be contained in a
separate file, to which the document (or documents) that use it make reference
(hence known as an "external script").
Client-side|LanguagesExample
There are many client-side scripting languages too.
JavaScript
VBScript
HTML (Structure)
CSS (Designing)
AJAX
jQuery etc.
Client-side | Ref. Example
// sample HTML code
<html>
<head>
<title>Client Side </title>
</head>
<body>
<h1>
Hello C# Corner
</h1>
</body>
</html>
III Year/VI Sem 49
IT-T62 Web Technology UNIT II
Server-side scripting
The Server is responsible for serving the web pages depending on the client/end
user requirement. It can be either static or dynamic.
The server-side environment that runs a scripting language is a web server.
A user's request is fulfilled by running a script directly on the web server to
generate dynamic HTML pages. This HTML is then sent to the client browser.
It is usually used to provide interactive web sites that interface to databases or
other data stores on the server.
The primary advantage to server-side scripting is the ability to highly customize
the response based on the user's requirements, access rights, or queries into
data stores.
Server-side|LanguagesExample
There are several languages that can be used for server-side programming:
PHP
ASP.NET (C# OR Visual Basic)
C++
Java and JSP
Python
Ruby on Rails and so on.
Sever Side Example code:
Using system
// namespace
class ServerSide
{
public static void Main()
{
System.Console.WriteLine(“Hello C# Corner”);
// printing a line
}
}
Introducing JavaScript
JavaScript is a scripting language developed by Netscape that is used to modify
web pages. Most JavaScript must be written in the HTML document between
<SCRIPT> tags.
You open with a <SCRIPT> tag, write your JavaScript, and write a closing
</SCRIPT> tag. Sometimes, as an attribute to script, you may add
“Language=JavaScript” because there are other scripting languages as well as
JavaScript that can be used in HTML.
JavaScript is object-oriented.
An Object in JavaScript is a resource that has specific characteristics known as
properties and provides several services known as methods and events.
JavaScript Properties
Note that JavaScript code did not need to be compiled – JavaScript is an
interpreted language
Interpreted vs. compiled languages: – Advantage: simplicity
Disadvantage: efficiency
Object Creation:
Objects are created using new expression
A constructor is a function
o When called via new expression, a new empty Object is created and
passed to the constructor along with the argument values
o Constructor performs initialization on object
Can add properties and methods to object
Can add object to an inheritance hierarchy
The Object() built-in constructor
o Does not add any properties or methods directly to the object
o Adds object to hierarchy that defines default toString() and valueOf()
methods (used for conversions to String and Number, resp.)
Property Creation
Assignment to a non-existent (even if inherited) property name creates the
property:
Object initializer notation can be used to create an object (using Object()
constructor) and one or more properties in a single statement:
Object Methods
• JavaScript functions are stored as values of type Object
• A function declaration creates a function value and stores it in a variable
(property of window) having the
• same name as the function
• A method is an object property for which the value is a function
Types of objects:
Math object
Number object
Date object
Boolean object
String object
Math object:
III Year/VI Sem 54
IT-T62 Web Technology UNIT II
Method Description
Sqrt(num) This method find the square root of number
Abs(num) This method returns absolute value of num
Ceil(num) This method returns the ceil value of number.for eg:ceil(10.3) return 11
Floor(num) This method returns the floor value of number.for eg:floor(10.3) return
10
Pow(a,b) This method compute the a power of b.
Min(a,b) Return the minimum value
Max(a,b) Return the maximum value
Number objects:
Method Description
MAX_VALUE Largest possible number displayed
MIN_VALUE Smallest possible number displayed
NAN When not a number than NAN is displayed
PI The value of PI gets displayed
POSTIVE_INFINITY The positive infinity gets displayed
NEGATIVE_INFINIT The negative infinity gets displayed
Y
Date Object:
1. getTime()
2. getDate()
3. getDay()
4. getMinute()
5. getHour()
6. getSecond()
7. getMilliseconds()
8. getUTCDate()
9. getUTCDay()
10. getUTCMinute()
11. getUTCSeconds()
12. getUTCMilliseconds()
13. setHour(hr,min,sec,ms);
14. setDate(value)
15. getUTCHour()
Boolean object:
This object is the simplest kind of object which is especially when we want
to represent true or false values.
String object:
Method Description
concat(str) This methods is used to concatenation of two string.
touppercase() This methods is used to convert lower case to upper case
tolowercase() This methods is used to convert upper case to lower case
value0f() This method returns the value of string
substring(begin,e This method return the substring specified by begin and end
nd) character
JavaScript Operators
Operators are used to create compound expressions from simpler expressions.
Operators can be classified according to the number of operands involved:
Unary: one operand (e.g., typeof i)
Prefix or postfix (e.g., ++i or i++ )
Binary: two operands (e.g., x + y)
Ternary: three operands (conditional )
Arithmetic Operator:
JavaScript Statements
• Expression statement: any statement that consists entirely of an expression –
Expression: code that represents a value
• Block statement: one or more statements enclosed in { } braces
• Keyword statement: statement beginning with a keyword, e.g., var or if
Flow Control
If…else
While
Do-while
For
Return
Break
Switch
If else:
The syntax of if else…
If(condition)
statement
else
statement
Example:
<html>
<head>
<title>if condition</title>
</head>
<body>
<script type=”text/javascript”>
var a,b,c;
a=10;b=20;c=30;
if(a>b)
{
if(a>c)
{
While statement:
While statements help us in implementing iterative logic of the program.
The syntax of while is as follows:
While(terminating Condition)
{
Some statement;
Stopping condition;
}
Example:
<html>
<head>
<title>while</title>
</head>
<body>
script type=”text/javascript”>
i=1;
Do while:
Do while same like that the while statement only one difference that is while
loop is check the condition and execute the statements but do while loop is execute
the statements and check the condition.
The syntax of while is as follows:
do
{
Some statement;
Stopping condition;
} While(terminating Condition);
For statement:
This is the most commonly used programming construct.
The syntax of for loop is:
For(initial condition;terminating condition;incremental)
Example:
<html>
<head>
<title>while</title>
</head>
<body>
script type=”text/javascript”>
for(i=1;i<=5;i++)
{
document.write(“Number +i+”,” square+(i+1)+”);
}</script>
</body>
Switch statement:
Switch case statement is basically to execute the desired choice.
The syntax of this control structure is similar to that in C or C++
Switch(variable name)
{
Case 0:
Break;
Case n:
Break;
}
Example:
<html>
<head>
<title>while</title>
</head>
<body>
script type=”text/javascript”>
d= new Date();
ch=d.getMoth();
switch(ch)
{
Case 1:
Document.write(“January”); Break;
Case 2:
Document.write(“February”); Break;
Case 3:
Document.write(“march”); Break;
Case 4:
Document.write(“April”); Break;
Case 5:
Document.write(“May”); Break;
Case 6:
JavaScript Events.
• An event is an occurrence of something potentially interesting to a script:
– Ex: mouseover and mouseout events
• An HTML intrinsic event attribute is used to specify a script to be called when
an event occurs
– Ex: onmouseover
– Name of attribute is on followed by event name
Event is an activity that represents a change in the environment.
An HTML event can be something the browser does, or something a user does.
Here are some examples of HTML events:
An HTML web page has finished loading
An HTML input field was changed
An HTML button was clicked
Often, when events happen, you may want to do something.
JavaScript lets you execute code when events are detected.
HTML allows event handler atributes, with JavaScript code, to be added to HTML
elements.
Output :
Mon May 18 2015 12:28:20 GMT+0530 (India Standard Time)
Functions in JavaScript
Declared within other functions. These are called “inner functions” and
are the main idea behind closures in JavaScript.
Built-in functions are almost completely concerned with validating
argument types which are commonly passed into functions or methods as
well as converting variables to and from these types.
This includes specifics such as NaN(), infinity(), and undefined(), as well as
functions for encoding and decoding data.
Functions can be created through several different techniques, and since
JavaScript uses first-class functions, they are treated as objects.
decodeURI(URI)
This functions used to decode the encoded URI.
For example:
Var uri=”my example.jsp?name”
Document.write(encodeURI(uri)+”<br/>”);
JavaScript Arrays
• The Array built-in object can be used to construct objects with special properties
and that inherit various methods
• Value of length is not necessarily the same as the actual number of elements
Methods inherited by array objects:
JavaScript Boolean:
The Boolean object is used to convert a non-Boolean value to a Boolean value (true
or false).
VB SCRIPTING:
VBScript is a server scripting language. It should not be used for scripting in the
browser. However Internet Explorer supports VBScript. This allows us to
experiment with VBScript in the browser, without the need for a web server. It is the
default scripting language in ASP (Active Server Pages). VBScript is a light version of
Microsoft's programming language Visual Basic
VBScript in HTML:
VBScript is inserted into HTML, between standard <script> and </script> tags.
Use the type attribute in the <script> tag to define the scripting language
"text/vbscript":
Syntax: <html>
<body>
<script type="text/vbscript">
...
</script>
</body>
</html>
VBScript Output:
You can declare VBScript variables with the Dim, Public or the Private statement as
Eg : Dim x
Dim carname
carname=some value
VBScript Function:
A Function procedure:
Conditional Statements:
Conditional statements are used to perform different actions for different decisions.
if...Then...Else:
Select Case:
You can also use the "Select Case" statement if you want to select one of many
blocks of code to execute:
Looping Statements:
Looping statements are used to run the same block of code a specified number of
times.
For...Next Loop:
Use the For...Next statement to run a block of code a specified number of times.
Eg: For i = 0 To 5
document.write("The number is " & i & "<br />")
A For Each...Next loop repeats a block of code for each item in a collection, or for
each element of an array.
Eg: <script type="text/vbscript">
Dim cars(2)
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x In cars
document.write(x & "<br />")
Next
</script>
Do...Loop:
The Do...Loop statement repeats a block of code while a condition is true, or until a
condition becomes true.
Eg: Do
some code
Loop While i>10
Exit a Do...Loop:
10. Cookies
A cookie is a small piece of information that is persisted between the
multiple client requests.A cookie has a name, a single value, and optional
attributes such as a comment, path and domain qualifiers, a maximum age,
and a version number.
How Cookie works
Types of Cookie
There are 2 types of cookies in servlets.
1. Non-persistent cookie
2. Persistent cookie
Non-persistent cookie
It is valid for single session only. It is removed each time when user closes the
browser.
Persistent cookie
It is valid for multiple session . It is not removed each time when user closes the
browser. It is removed only if user logout or signout.
Advantage of Cookies
1. Simplest technique of maintaining the state.
2. Cookies are maintained at client side.
Disadvantage of Cookies
1. It will not work if cookie is disabled from the browser.
2. Only textual information can be set in Cookie object.
index.html
<form action="servlet1" method="post">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>
FirstServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse respon
se){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
out.close();
}catch(Exception e){System.out.println(e);}
}
}
SecondServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SecondServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response
){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie ck[]=request.getCookies();
out.print("Hello "+ck[0].getValue());
out.close();
}catch(Exception e){System.out.println(e);}
}
web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
</web-app>
Enrich your Web design project with multimedia elements to captivate and
inform Web page visitors, regardless of which browser they are using.
Sound files, pictures, animations and video footage are considered forms of
multimedia that you can combine to enhance a website if you take steps to
overcome accessibility challenges that threaten the inherent advantages of
using multimedia elements.
Be sure that these objects are accessible to a broad range of website visitors
to maximize their advantages.