0% found this document useful (0 votes)
40 views13 pages

Unit-3 Web Tech

Uploaded by

VAIBHAV BADHANI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views13 pages

Unit-3 Web Tech

Uploaded by

VAIBHAV BADHANI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Unit-3 Scripting

Introduction of Javascript

JavaScript can be used for Client-side developments as well


as Server-side developments.

JavaScript is both an imperative and declarative type of language.

JavaScript contains a standard library of objects, like Array, Date,


and Math, and a core set of language elements like operators, control
structures, and statements.

How to Link JavaScript File in HTML?

JavaScript can be added to HTML file in two ways:

 Internal JS: We can add JavaScript directly to our HTML file by


writing the code inside the <script> tag. The <script> tag can either
be placed inside the <head> or the <body> tag according to the
requirement.
 External JS: We can write JavaScript code in another file having an
extension.js and then link this file inside the <head> tag of the HTML
file in which we want to add this code.

Syntax

<script>
// JavaScript Code
</script>
Example:

<!DOCTYPE html>
<html lang="en">

<head>
<title>
Basic Example to Describe JavaScript
</title>
</head>

<body>

<!-- JavaScript code can be embedded inside


head section or body section -->
<script>
console.log("Welcome to G L Bajaj");
</script>
</body>

</html>

Output: The output will display on the console.

Welcome to G L Bajaj
Features of JavaScript

 JavaScript was created in the first place for DOM manipulation.


Earlier websites were mostly static, after JS was created dynamic
Web sites were made.
 Functions in JS are objects. They may have properties and methods
just like other objects. They can be passed as arguments in other
functions.
 Can handle date and time.
 Performs Form Validation although the forms are created using
HTML.
 No compiler is needed.

JavaScript Form

Forms are the basics of HTML. We use HTML form element in order to
create the JavaScript form. For creating a form, we can use the following
sample code:

<html>
<head>
<title> Login Form</title>
</head>
<body>
<h3> LOGIN </h3>
<formform ="Login_form" onsubmit="submit_form()">
<h4> USERNAME</h4>
<input type="text" placeholder="Enter your email id"/>
<h4> PASSWORD</h4>
<input type="password" placeholder="Enter your password"/></br></br>
<input type="submit" value="Login"/>
<input type="button" value="SignUp" onClick="create()"/>
</form>
</html>
AJAX

 AJAX is an acronym for Asynchronous JavaScript and XML.


 AJAX allows you to send and receive data asynchronously without
reloading the web page. So it is fast.
 AJAX allows you to send only important information to the server
not the entire page. So only valuable data from the client side is
routed to the server side. It makes your application interactive and
faster.
 AJAX allows web pages to be updated asynchronously by
exchanging data with a web server behind the scenes. This means
that it is possible to update parts of a web page, without reloading
the whole page.

How AJAX Works

 1. An event occurs in a web page (the page is loaded, a button is


clicked)
 2. An XMLHttpRequest object is created by JavaScript
 3. The XMLHttpRequest object sends a request to a web server
 4. The server processes the request
 5. The server sends a response back to the web page
 6. The response is read by JavaScript
 7. Proper action (like page update) is performed by JavaScript
VB Script

VBScript is an active scripting language introduced by Microsoft. It is


developed based on Visual Basic and is also called a Visual Basic
scripting language. It does not support all browsers, supports only
Internet Explorer. It is generally used in Microsoft environments and
uses a component object model to access system objects and variables
of the environment.

Difference between JavaScript and VBScript

S.No. JavaScript VBScript

It was developed by
It was developed by Netscape.
1. Microsoft.

It does job as both server-


It does job as a client-side
side and client-side
scripting language.
2.. scripting language.

It supports all web browsers and it It does not support all


is a default scripting language in browsers, supports only
3. mostly browsers. Internet Explorer.

While it uses different


It uses the same operator for
operators for various
various operations.
4. operations.

It uses Function and End


It uses curly braces for declaration
function for declaration of
of functions.
5. functions.

JavaScript file has the file VBScript file has the file
6. extension “.js”. extensions “.vbs” or “.vba”.
Java Beans

Class in Java

JavaBeans are classes that encapsulate many objects into a single object
(the bean). It is a Java class that should follow the following conventions:

1. Must implement Serializable.


2. It should have a public no-arg constructor.
3. All properties in java bean must be private with public getters and
setter methods.

A simple example of JavaBean Class is mentioned below:

// Java program to illustrate the

// structure of JavaBean class

public class TestBean {

private String name;

public void setName(String name) {

this.name = name;

public String getName() { return name; }

}
Advantages of JavaBeans

1. Reusability: JavaBean is designed to be a reusable component


that can be easily integrated into other applications, which can
save development time and effort.
2. Encapsulation: JavaBean encapsulates data and behavior, which
helps to keep the code modular and easy to maintain. This makes
it easier to modify and extend the code without affecting other
parts of the system.
3. Standardization: JavaBean follows a set of conventions and
standards, which makes it easier to understand and work with
code written by others.
4. Compatibility: JavaBean is compatible with a wide range of Java
technologies and frameworks, which makes them highly versatile
and adaptable to different types of projects.
5. Persistence: JavaBeans can be serialized and stored on a disk or
sent over the network, which makes it easy to save and load data
in a standardized format.
6. Integration: JavaBean can be easily integrated into different Java-
based technologies and architectures, such as JavaServer Faces,
Spring, or Java EE, which makes them highly flexible and
compatible.
Disadvantages of Java Beans

1. Complexity: JavaBean can be complex to develop and maintain,


especially if they have a lot of properties and methods. This
complexity can lead to longer development times and an increased
risk of bugs.
2. Limited functionality: JavaBean is primarily designed to
encapsulate data. It can also include behavior through methods. It
is not well-suited for more complex tasks such as multithreading,
networking, or user interface programming.
3. Lack of flexibility: JavaBean is designed to use as a standalone
component. This means that it can be limited in its ability to
interact with other components and systems.
4. Tight coupling: JavaBean can introduce tight coupling between
components. This makes it difficult to modify or extend the system
in the future.

JavaBeans Properties

A JavaBean property is a named attribute that can be accessed by the


user of the object. The attribute can be of any Java data type, including
the classes that you define.

A JavaBean property may be read, write, read only, or write only.


JavaBean properties are accessed through two methods in the
JavaBean's implementation class –

S.No. Method & Description

getPropertyName()
For example, if property name is firstName, your method name
1
would be getFirstName() to read that property. This method is
called accessor.

setPropertyName()
For example, if property name is firstName, your method name
2
would be setFirstName() to write that property. This method is
called mutator.

A read-only attribute will have only a getPropertyName() method, and a


write-only attribute will have only a setPropertyName() method.
Enterprise Java Beans (EJB)

 Enterprise Java Beans (EJB) is one of the several Java APIs for standard
manufacture of enterprise software.
 EJB is a server-side software element that summarizes business logic of an
application.
 Enterprise Java Beans web repository yields a runtime domain for web
related software elements including computer reliability, Java Servlet
Lifecycle (JSL) management, transaction procedure and other web services.
 The EJB enumeration is a subset of the Java EE enumeration.
 The EJB enumeration aims to provide a standard way to implement the
server-side business software typically found in enterprise applications.
 Such machine code addresses the same types of problems, and solutions to
these problems are often repeatedly re-implemented by programmers.
 EJB application is deployed on the server, so it is called server side
component also.
Types of Enterprise Java Beans

There are three types of EJB:

1. Session Bean:

Session bean contains business logic that can be invoked by local, remote or
webservice client. There are two types of session beans: (i) Stateful session bean
and (ii) Stateless session bean.

 (i) Stateful Session bean

Stateful session bean performs business task with the help of a state. Stateful
session bean can be used to access various method calls by storing the
information in an instance variable. Some of the applications require information
to be stored across separate method calls. In a shopping site, the items chosen
by a customer must be stored as data is an example of stateful session bean.

 (ii) Stateless Session bean :

Stateless session bean implement business logic without having a persistent


storage mechanism, such as a state or database and can used shared data.
Stateless session bean can be used in situations where information is not
required to used across call methods.

2. Message Driven Bean: Like Session Bean, it contains the business logic but it
is invoked by passing message.

3. Entity Bean: It summarizes the state that can be remained in the database. It is
deprecated. Now, it is replaced with JPA (Java Persistent API). There are two
types of entity bean:

 (i) Bean Managed Persistence :

In a bean managed persistence type of entity bean, the programmer has to


write the code for database calls. It persists across multiple sessions and
multiple clients.

 (ii) Container Managed Persistence :

Container managed persistence are enterprise bean that persists across


database. In container managed persistence the container take care of
database calls.
Use of Enterprise Java Beans

Application needs Remote Access. In other words, it is distributed.


Application needs to be scalable. EJB applications supports load balancing,
clustering and fail-over.
Application needs encapsulated business logic. EJB application is
differentiated from demonstration and persistent layer.

Advantages of Enterprise Java Beans

1. EJB repository yields system-level services to enterprise beans, the bean


developer can focus on solving business problems. Rather than the bean
developer, the EJB repository is responsible for system-level services such as
transaction management and security authorization.

2. The beans rather than the clients contain the application’s business logic, the
client developer can focus on the presentation of the client. The client developer
does not have to code the pattern that executes business rules or access
databases. Due to this the clients are thinner which is a benefit that is particularly
important for clients that run on small devices.

3. Enterprise Java Beans are portable elements, the application assembler can
build new applications from the beans that already exists.

Disadvantages of Enterprise Java Beans

1. Requires application server


2. Requires only java client. For other language client, you need to go for
webservice.
3. Complex to understand and develop EJB applications.
Difference between Java Beans and Enterprise Java Beans (EJB)
S.No. Java Beans Enterprise Java Beans (EJB)
1. Javabeans is a component EJB is a component technology; it
technology to create universal neither reconstructs nor enhances
Java components. the original JavaBean specification.
2. JavaBeans are designed for a EJBs are remotely executable
single process and are localized components or business objects.
3. JavaBeans have not any definite EJBs may be transactional and
support exists for transactions. transactional support is provided by
the EJB servers.
4. There is no further category of Enterprise JavaBeans are
Java Beans. categorized into two types – session
beans and entity beans.
5. JavaBeans may be visible or non- An EJB is a non-visual isolated
visible components. Visual GUI object.
component (Button, listbox,
graphics) are examples of
JavaBeans.
6. JavaBeans are mainly designed to EJBs are deployed on the server-
run on the client side whereas one side only.
can develop server side
JavaBeans.
JavaBeans API
 The java.beans package provides support for long-term persistence - reading
and writing a bean as a textual representation of its property values.
 The property values are treated as beans, and are recursively read or written
to capture their publicly available state.
 This approach is suitable for long-term storage because it relies only on public
API, rather than the likely-to-change private implementation.
 You read and write beans in XML format using
the XMLDecoder and XMLEncoder classes, respectively. One notable feature
of the persistence scheme is that reading in a bean requires no special
knowledge of the bean.
 The JavaBeans API and its implementation are contained in the java. beans
package. A few of the classes are used by beans while they run in an
application.
 For example the event classes are used by beans that fire property and
vetoable change events (see PropertyChangeEvent ).

You might also like