Web Tech Notes (Unit-3 & 4)
Web Tech Notes (Unit-3 & 4)
Scripting
1. JavaScript is a scripting language which enables web authors to design
Inter active sites.
2. JavaScript can interact with HTML source code, enabling web authors
to build their sites with dynamic content.
3. JavaScript is an open source language that anyone can use without
purchasing a license.
1. When the browser loads a web page, the HTML parser creates the DOM.
2. Whenever parser encounters JavaScript directive, it is handed over the
JavaScript engine and loads the external and inline code.
3. After HTML and CSS parsing is completed, JavaScript is executed in
order they were found in web page and DOM is updated and rendered
by the browser.
Strengths/Advantages of JavaScript :
1. An interpreted language : JavaScript is an interpreted language,
which requires no compilation steps.
2. Quick development : JavaScript does not require time consuming
compilations, scripts can be developed in a short period of time.
3. Performance :
a. JavaScript can be written such that the HTML files are fairly compact
and quite small.
b. It minimizes storage requirements on the web server and download
time for the client.
4. Easy debugging and testing : Being an interpreted language, scripts
in JavaScript are tested line by line and the errors are also listed as they
are encountered.
Weakness/Disadvantages of JavaScript :
1. There are issues of incompatibility of several scripting that result in
website overloading.
2. Different layout engines may render JavaScript differently resulting in
inconsistency in terms of functionality and interface.
3. JavaScript is also a common tool for the web hackers; they use scripts
injection to hack a site.
4. JavaScript is light, somehow too much of JavaScript can slow down the
page loading of a website.
Java Script DOM -
Script :
1. First the user will enter the value in the form field.
2. Then, browser will ensure that the value provided by user is correct and
is valid so that successful validation can be done.
3. JavaScript used in the web page uniquely defines all the special
functionalities in the client browser.
4. By default, if there is a validation error then an error or pop-up message
is shown by the browser.
5. If there is no error then the validation on client-side will be successfully
performed.
For example :
If a form field (fname) is empty, validateform function alerts a message,
and returns false, to prevent the form from being submitted:
function validateForm() {
var x = document.forms[“myForm”][“fname”].value;
if (x == “ ”) {
alert(“Name must be filled out”);
return false;
}
}
The JavaScript function is called when the form is submitted :
<form name=“myForm” action=“/action_page.php” onsubmit=“return
validateForm()” method=“post”>
Name: <input type=“text” name=“fname”>
<input type=“submit” value=“Submit”>
</form>
Scripting language :
1. A scripting language is a programming language designed for integrating
and communicating with other programming languages.
2. Some of the most widely used scripting languages are JavaScript,
VBScript, PHP, Perl, Python, Ruby, ASP.
JavaScript is used because :
a. It is executed on client side.
b. It saves bandwidth on web server.
c. It is written into an HTML page.
Syntax :
if (condition)
{
code to be executed if condition is true
}
For example :
<script type = “text/javascript”>
var d = new Date();
var time = d.getHours();
if (time<10)
{
document.write (“<b>Good morning to all</b>”);
}
</script>
2. If...else statement : If...else statement is used when we do not confirm
about the condition that is true or not.
Syntax :
if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
For example :
<script type = “text/javascript”>
//If the time is less than 10, print “Good Day” Otherwise “Good Night”
var d = new Date ();
var time = d.getHours ();
if (time < 10)
{
document.write (“Good Day”);
}
else
{
document.write (“Good Night”);
}
</script>
3. If...else if...else statement : We can use the if...else if...else statement
if we want to select one from many sets of lines with different condition.
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
}
For 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 afternoon</b>”);
}
else
{
document.write (“<b>Good night</b>”);
}
</script
Object in JavaScript :
1. Built-in objects : These objects are used quite extensively for data
processing in JavaScript. Following are some built-in object :
a. String object :
i. The string object enables programs to work with and manipulate
string.
ii. It provide methods such as : big(), blink(), bold(), italics(),
charAt(), touppercase(), tolowercase() and substring().
b. Math object :
i. The math object provides some commonly used methods such
as : sqrt(num), abs(num), sin(num), cos(num), tan(num),
exp(num), min(a, b), max(a, b), log(num), pow(a, b), floor(num),
ceil(num) etc.
c. Date object :
i. The date object enables JavaScript programmers to create an
object that contains information about a particular date and
provides a set of methods to work with that information.
ii. Syntax :
var mydate = new Date(<parameters>);
iii. If the parameter left empty, it indicates current date and time.
iv. The date object provides some methods which are : getDate(),
setDate(), getHours(), setHours(), getTime(), setTime(),
getDay(), setDay(), getMinutes(), setMinutes(), getSecond(),
setSecond().
d. Array object :
i. The array object stores multiple values in a single variable.
ii. Syntax :
var fruits = new Array( “apple”, “orange”, “mango” );
2. User-defined objects :
a. A user-defined object is also associated with properties and
methods, which belong to it.
b. The user-defined object would also require methods that will
allow
the storage of name, age and salary of the employee object.
function Employee(name, age, salary)
{
this.name = name;
this.age = age;
this.salary = salary;
}
Introduction of AJAX –
2 HTTP request
XMLHttp Request Business logic
implementation
IP Addressing-
1. The IP address is a network layer address that uniquely identifies each
computer on network.
2. Each TCP/IP host is identified by a logical IP address.
3. The IP address identifies a system’s location on the network. An IP
address must be globally unique and have a uniform format.
4. Each IP address includes a network ID and a host ID.
i. The network ID (also known as a network address) identifies the
systems that are located on the same physical network ID. The
network ID must be unique to the internetwork.
ii. The host ID (also known as a host address) identifies a workstation,
server, router, or other TCP/IP host within a network. The address
for each host must be unique to the network ID.
5. The use of the term network ID refers to any IP network ID, whether
it is class-based, a subnet, or a super net.
An internet address is made of four
bytes (32 bits) that define a host's
connection to a network.
Class
type Netid Hostid
IP Address-
IP address is classified as:
1. Class A :
i. Class A addresses are assigned to networks with a very large
number of hosts.
ii. The high-order bit in a class A address is always set to zero.
iii. The next seven bits (completing the first octet) complete network
ID. The remaining 24 bits (the last three octets) represent the
host ID.
iv. This allows for 126 networks and 16,777,214 i.e., 2 24 hosts per
network.
2. Class B :
i. Class B addresses are assigned to medium-sized to large-sized
networks.
ii. The two high-order bit in a class B address are always set to binary
10.
iii. The next 14 bits (completing the first two octets) complete the
network ID. The remaining 16 bits (last two octets) represent the
host ID.
iv. This allows for 16,384 networks and 65,534 hosts per network.
byte 1 byte 2 byte 3 byte 4
3. Class C :
i. Class C addresses are used for small networks.
ii. The three high-order bits in a class C address are always set to
binary 110.
iii. The next 21 bits (completing the first three octets) complete the
network ID. The remaining 8 bits (last octet) represent the host
ID.
iv. This allows for 2,097, 152 networks and 254 hosts per network.
From To
Class A 0.0.0.0 127 . 255 . 255 . 255
Netid Hostid Netid Hostid
Class B 128 . 0 . 0 . 0 191 . 255 . 255 . 255
Netid Hostid Netid Hostid
Class C 192 . 0 . 0 . 0 223 . 255 . 255 . 255
Netid Hostid Netid Hostid
Class D 224 . 0 . 0 . 0 239 . 255 . 255 . 255
Group address Netid Hostid
Class E 240 . 0 . 0 . 0 255 . 255 . 255 . 255
Undefined Undefined
Figure
4. Class D :
i. Class D addresses are reserved for IP multicast addresses.
ii. The four high-order bits in a class D address are always set to
binary 1110.
iii. The remaining bits are for the address that interested hosts will
recognize.
iv. Microsoft supports class D addresses for applications to multicast
data to multicast-capable hosts on an internetwork.
5. Class E : Class E addresses are experimental addresses reserved for
future use. The high-order bits in a class E address are set to 1111
Inet Address class
1. The InetAddress class is used to encapsulate both the numerical IP
address and the domain name for that address.
2. The InetAddress class hides the number inside.
3. InetAddress can handle both IPv4 and IPv6 addresses.
4. The InetAddress class has no visible constructors.
Factory Methods-
1. Factory methods are used to create an InetAddress object.
2. Factory method is a static method in a class and return an instance of
that class.
3. Three commonly used InetAddress factory methods are as follows :
a. The getLocalHost() : This method simply returns the InetAddress
object that represents the local host.
b. The getByName() : This method returns an InetAddress for a
host name passed to it. If this method is unable to resolve the
host name then, they throw an UnknownHostException.
c. The getAllByName() : This method returns an array of
InetAddresses that represent all of the addresses that a particular
name resolves to. It will also throw an UnknownHostException
if it cannot resolve the name to at least one address.
Instance Method-
1. Instance method is a method defined in a class and only accessible
through the object of the class.
2. The InetAddress class has several instance methods, which can be
used on the objects.
3. Following are the object returned by the methods which are as follows :
a. Boolean equals(Object other) : It returns true if this object
has the same Internet address as other. Otherwise, it returns
false.
b. Byte[ ] getAddress() : It returns a byte array that represents
the object’s Internet address in network byte order.
c. String getHostAddress() : It returns a string that represents
the host address associated with the Inet Address object.
d. String getHostName() : It returns a string that represents the
host name associated with the InetAddress object.
e. String toString() : It returns a string that lists the host name
and the IP address.
TCP/IP Client Sockets
1. TCP/IP client sockets are used to implement bi-directional, point-to-
point, stream-based connections between hosts on the Internet.
2. A socket can be used to connect Java I/O system to other programs
that may reside either on the local machine or on any other machine
on the Internet.
3. The creation of a Socket object implicitly establishes a connection
between the client and server.
4. Following are the two constructors used to create client socket :
a. Socket(String hostName, int port) : Creates a socket connecting
the local host to the named host, port and can throw an Unknown
HostException or an IOException.
b. Socket(InetAddress ipAddress, int port) : Creates a socket
using a pre-existing InetAddress object, a port and can throw an
IOException.
5. Following methods are used by TCP/IP client socket :
a. InetAddress getInetAddress() : Returns the InetAddress
associated with the Socket object.
b. Int getPort() : Returns the remote port to which the Socket
object is connected.
c. Int getLocalPort() : Returns the local port to which the Socket
object is connected.
URL
1. URL is an acronym for Uniform Resource Locator.
2. It points to a resource on the World Wide Web (WWW).
3. A URL contains many information like protocol name, server name,
port number and file name.
4. The URL is represented by an URL class.
5. Consider the following URL :
http://www.quantumpage.com/aktu-paper.html
a. Protocol : In this case, http is the protocol.
b. Server name or IP address : In this case, www.quantumpage.com
is the server name.
c. Port number : It is an optional attribute. If we write http//
www.quantumpage.com:80/aktu-papers.html/, 80 is the port
number. If port number is not mentioned in the URL, it returns
– 1.
d. File name or directory name : In this case, aktu-papers.html
is the file name.
Following are the method provided by java.net.URL class :
S. No. Method Description
Socket Programming
1. Java socket programming is used for communication between the
applications running on different JRE.
2. Java socket programming can be connection-oriented or connection-
less.
3. Socket and Server Socket classes are used for connection-oriented socket
programming and Datagram Socket and Datagram Packet classes are
used for connection-less socket programming.
4. Sockets provide the communication mechanism between two computers
using TCP.
5. A client program creates a socket on its end of the communication and
attempts to connect that socket to a server.
6. The client in socket programming must know :
a. IP address of server.
b. Port number.
Datagram Sockets
Advantages of EJB :
1. It can run in multithreaded environment.
2. It contains only business logic.
3. EJB provides distributed transaction support.
4. It provides portable and scalable solutions of the problem.
5. It provides a mechanism to store and retrieve data in a persistent way.
Disadvantages of EJB :
1. It requires application server.
2. It requires only Java client. For other language client, we need to go for
web service.
3. It is complex to understand and develop EJB applications.
EJB Architecture
Types of EJB -
1. Entity bean : Entity beans represent persistent data storage. Entity
beans are used for modeling the business concept.
Step 5 :
1. Start and run the Bean Box.
2. Load JAR file into Bean Box by selecting “Loadjar...” under the File
menu.
Step 6 :
1. After the file selection dialog box is closed. Then “SimpleBean” appear
at the bottom of the toolbox window.
2. Select SimpleBean.jar.
3. Cursor will change to a plus. In the middle BeanBox window, we can
now click to drop in what will appear to be a coloured rectangle.
Step 7 : Try changing the red box colour with the Properties windows.
Step 8 : Choose “Events” under the “Edit” menu in the middle window to see
what events SimpleBean can send. These events are inherited from
java.awt.Canvas.
Entity Beans-
1. Entity beans are objects that represent a persistence storage
mechanism.
2. Each entity beans has underlying table in a relational database and each
row in the table represents the instance of the bean.
Working of JDBC :
1. All Java application establishes connection with the data source and
invokes classes and interfaces from JDBC driver for sending queries to
the data source.
2. The JDBC driver connects to corresponding database and retrieves the
result.
3. These results are based on SQL statements, which are then returned to
Java applications.
4. Java application then uses the retrieved information for further
processing.
Components of JDBC –
1.Driver manager :
a.When Java applications need connection to the database it invokes
the Driver Manager class.
b. This class then loads JDBC drivers in the memory. The driver
manager also attempts to open a connection with the desired database.
2. Connection :
a. This is an interface which represents connectivity with the datasource.
b. The connection is used for creating the statement instance.
3. Statement :
a. This interface is used for representing the SQL statements.
b. Some SQL statements are :
SELECT *FROM students _ table;
UPDATE students _table set name = ‘Nitin’ WHERE roll _ no = ‘1’;
c. There are two specialized statement types : Prepared Statement
and callable Statement.
4. Result Set :
a. This interface is used to represent the database resultSet.
b. After using SELECT SQL statement, the information obtained from
the database can be displayed using Result Set.
5. SQL exception : For handling SQL exceptions, this interface is used.
JDBC Architecture-
Application
JDBC-Driver Manager
ODBC-Driver Manager
Application
JDBC
Socket connection
JAVA based (DBMS specific
DBMS
socket driver protocol)
Server
}
catch (SQLException e) {
...
}
finally {
pstmt.close();
}
6. All parameters in JDBC are represented by the symbol, which is
known as the parameter marker. We must supply values for every
parameter before executing the SQL statement.
7. To close the Prepared Statement object a simple call to the close()
method is made. If we close the connection object first, it will close
the Prepared Statement object as well.
Stored Procedure in Java
b. Function :
i. A function is one which contains n number of block of
statements to perform some operation and it returns a single
value only.
ii. Syntax for creating a function :
create function (a in number, b in number) return <return
type>
as/is
n1 out number;
begin
n1:=a+b; return (n1);
end;
Types of transaction-
1. Local transaction : A local transaction means that all operations in a
transaction are executed against one database.
For example : If we transfer money from first account to second account
and both accounts belongs to same bank then transaction is local
transaction.