Java Beans | 2016-2018
Batch
CustomerHome
Customer
CustomerBean
Container
Integer
False
myA ddress
myName
myCreditCard
This role represents everyone who is allowed full access to the Customer bean.
everyone
everyone
CustomerBean
*
All methods require a transaction
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 5/22Java Beans | 2016-2018
Batch
CustomerBean
*
Required
4,2 SESSION BEAN
A session bean represents a single client inside the Application Server. To access an
application that is deployed on the server, the client invokes the session bean’s methods.
The session bean performs work for its client, shielding the client from complexity by
executing business tasks inside the server.
As its name suggests, a session bean is similar to an interactive session. A session bean is
not shared; it can have only one client, in the same way that an interactive session can
have only one user. Like an interactive session, a session bean is not persistent. (That is,
its data is not saved to a database.) When the client terminates, its session bean appears to
terminate and is no longer associated with the client.
STATE MANAGEMENT MODES,
‘There are two types of session beans: stateful and stateless.
4.2.1 Stateful Session Beans
The state of an object consists of the values of its instance variables, In a stateful session
bean, the instance variables represent the state of a unique client-bean session. Because
the client interacts (“talks”) with its bean, this state is often called the conversational
state, The state is retained for the duration of the client-bean session. If the client removes
the bean or terminates, the session ends and the state disappears. This transient nature of
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 6/22Java Beans | 2016-2018
Batch
the state is not a problem, however, because when the conversation between the client
and the bean ends there is no need to retain the state.
‘As an example, the HotelClerk bean can be modified to be a stateful bean which can
maintain conversational state between method invocations. This would be useful, for
example, if you want the HotelClerk bean to be able to take many reservations, but then
process them together under one credit card. This occurs frequently, when families need
to reserve two or more rooms or when corporations reserve a block of rooms for some
event.
Below the HotelClerkBean is modified to be a stateful bean:
import javax.ejb.SessionBean;
import javax.naming,InitialContext;
public class HotelClerkBean implements SessionBean {
Initial Context jndiContext;
Meonversational-state
Customer cust;
Vector resVector = new Vector();
public void ejbCreate(Customer customer) {}
cust = customer;
,
public void addReservation(Name name, RoomInfo ri,
Date from, Date to) {
ReservationInfo resInfo =
new ReservationInfo(name,ri,from,to);
resVector.addElement(resinfo);
}
public void reserveRooms() {
CreditCard card = cust.getCreditCard();
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 7/22Java Beans | 2016-2018
Batch
Enumeration resEnum = resVector.elements();
while (resEnum.hasMoreElements()) {
ReservationInfo resinfo =
(ReservationInfo) resEnum.nextElement();
RoomHome roomHome = (RoomHome)
getHome("java:comp/env/ejb/RoomEJB", RoomHome.class);
Room room =
roomHome. findByPrimaryKey(resInfo.roomInfo.getID();
double amount = room.getPrice(resInfo.trom,restInfo.to);
CreditServiceHome creditHome = (CreditServiceHome)
getHome("java:comp/env/ejb/CreditServiceEJB",
CreditServiceHome.class);
CreditService creditAgent = creditHome.create();
creditAgent.verify(card, amount);
ReservationHlome resHome = (ReservationHome)
getHome("java:comp/env/ejb/ReservationEJB",
ReservationHome.class);
Reservation reservation =
resHome.create(resInfo.getName(),
resinfo.roominfo,resInfo.from,resinfo.to);
}
public RoomInfo[] availableRooms(Location loc,
Date from, Date to) {
{i Make an SQL call to find available rooms
}
private Object getHome(String path, Class type) {
Object ref = jndiContext.Jookup(path);
return PortableRemoteObject.narrow(ref.type);
y
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 8/22,Java Beans | 2016-2018
Batch
In the statefill version of the HotelClerkBean class, the conversational state is the
Customer reference, which is obtained when the bean is created, and the Vector of
ReservationInfo objects.
By maintaining the conversational state in the bean, the client is absolved of the
responsibility of keeping track of this session state, The bean keeps track of the
reservations and processes them in a batch when the serverRooms() method is invoked.
To conserve resources, stateful session beans may be passivated when they are not
in use by the client, Passivation in stateful session beans is different than for entity beans.
In statefill beans, passivation means the bean conversational-state is written to a
secondary storage (often disk) and the instance is evicted from memory, The client's
reference to the bean is not affected by passivation; it remains alive and usable while the
bean is passivated.
When the client invokes a method on a bean that is passivated, the container will
activate the bean by instantiating a new instance and populating its conversational state
with the state written to secondary storage. This passivation/activation process is often
accomplished using simple Java serialization but it can be implemented in other
proprietary ways as long as the mechanism behaves the same as normal serialization.
(One exception to this is that transient fields do not need to be set to their default initial
values when a bean is activated.) Stateful session beans, unlike stateless beans, do use the
ejbActivate() and ejbPassivate() methods. The container will invoke these methods to
notify the bean when it's about to be passivated (ejbPassivate()) and immediately
following activation ejbActivate()). Bean developers should use these methods to close
open resources and to do other clean-up before the instance's state is written to secondary
storage and evicted from memory.
The ejbRemove() method is invoked on the stateful instance when the client
invokes the remove() method on the home or remote interface. The bean should use the
ejbRemove() method to do the same kind of clean-up performed in the ejbPassivate()
method.
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 9/22Java Beans | 2016-2018
Batch
4.2.1 Stateless Session Beans
A stateless session bean does not maintain a conversational state with the client. When a
client invokes the methods of a stateless bean, the bean’s instance variables may contain
a state specific to that client, but only for the duration of the invocation. When the
method is finished, the client-specific state should not be retained. Clients may, however,
change the state of instance variables in pooled stateless beans, and this state is held over
to the next invocation of the pooled stateless bean. Except during method invocation, all
instances of a stateless bean are equivalent, allowing the EJB container to assign an
instance to any client. That is, the state of a stateless session bean should apply accross all
clients.Because stateless ses
sion beans can support multiple clients, they can offer better
scalability for applications that require large numbers of clients. Typically, an application
requires fewer stateless session beans than stateful session beans to support the same
number of clients. A stateless session bean can implement a web service, but other types
of enterprise beans cannot.
An example of a stateless session bean is a CreditService bean, representing a credit
service that can validate and process credit card charges. A hotel chain might develop a
CreditService bean to encapsulate the process of verifying a credit card number, making a
charge, and recording the charge in the database for accounting purposes. Below are the
remote and home interfaces for the CreditService bean:
iH remote interface
public interface CreditService extends javax.ejb.EJBObject {
public void verify(CreditCard card, double amount)
throws RemoteException, CreditServiceException;
public void charge(CreditCard card, double amount)
throws RemoteException, CreditServiceException;
}
‘home interface
public interface CreditServiceHome extends java.ejb.EJBHome {
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 10/22Java Beans | 2016-2018
Batch
public CreditService create()
throws RemoteException, CreateException;
3
The remote interface, CreditService, defines two methods, verify() and charge(), which
are used by the hotel to verify and charge credit cards, The hotel might use the verify()
method to make a reservation, but not charge the customer. The charge() method would
be used to charge a customer for a room. The home interface, CreditServiceHome
provides one create() method with no arguments. All home interfaces for stateless session
beans will define just one method, a no-argument create() method, because session beans
do not have find methods and they cannot be initiated with any arguments when they are
created. Stateless session beans do not have find methods, because stateless beans are all
equivalent and are not persistent. In other words, there is no unique stateless session
beans that can be located in the database, Because stateless session beans are not
persisted, they are transient services. Every client that uses the same type of session bean
gets the same service.
Below is the bean class definition for the CreditService bean. This bean encapsulates
access to the Acme Credit Card processing services. Specifically, this bean accesses the
Acme secure Web server and posts requests to validate or charge the customer's credit
card,
import javax.ejb.SessionBean;
public class CreditServiceBean implements SessionBean {
URL acmeURL;
HttpURLComnection acmeCon;
public void ejbCreate() {
try {
Initial Context jndiContext = new InitialContext();
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 11/22Java Beans | 201
Batch
2018
URL acmeURL = (URL)
jndiContext.lookup(("java:comp/ejb/env/urliacme");
acmeCon = acmeURL.openConnection();
}
catch (Exception e) {
throws new EJBException(e);
Hy
public void verify(CreditCard card, double amount) {
String response = post("'verify:" + card,postString() +
"+ amount);
if (response.substring(""approved")== -1)
throw new CreditServiceException("denied");
3
public void charge(CreditCard card, double amount)
throws CreditCardException {
String response ~ post("charge:" + card.postStringQ) +
"+ amount);
if (response substring("“approved")== 1)
throw new CreditServiceException("“denied");
}
private String post(String request) {
try {
acmeCon.connect();
acmeCon.setRequestMethod("POST "+request);
String response = acmeCon. getResponseMessage();,
3
catch (IOException ive) {
throw new EJBException(ioe);
}
3
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 12/22Java Beans | 2016-2018
Batch
public void ejbRemove() {
acmeCon.disconnect();
3
public void setSessionContext(SessionContext entx) {}
public void ejbActivate() {}
public void ejbPassivate() {}
}
When to use session beans
In general, you should use a session bean if the following circumstances hold:
* Atany given time, only one client has access to the bean instance.
* The state of the bean is not persistent, existing only for a short period (perhaps a
few hours).
* The bean implements a web service
Statefull session beans are appropriate if any of the following conditions are true:
‘+ The bean’s state represents the interaction between the bean and a specific client.
‘© The bean needs to hold information about the client across method invocations.
The bean mediates between the client and the other components of the application,
presenting a simplified view to the
To improve performan
choose a stateless session bean if it has any of these traits:
+ The bean’s state has no data for a specific client.
‘+ Ina single method invocation, the bean performs a generic task for all clients
For example, use a stateless session bean to send an email that confirms an online
order
4.3 ENTITY BEANS
The entity bean is one of three primary bean types: entity, session and Message
Driven. The entity Bean is used to represent data in the database. It provides an object-
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 13/22Java Beans | 2016-2018
Batch
oriented interface to data that would normally be accessed by the IDBC or some other
back-end API. More than that, entity beans provide a component model that allows bean
developers to focus their attention on the business logic of the bean, while the container
ns, and access control.
takes care of managing persistence, transact
There are two basic kinds of entity beans: container-managed persistence (CMP)
and bean-managed persistence (BMP). With CMP, the container manages the
persistence of the entity bean, With BMP, the entity bean contains database access code
(usually JDBC) and is responsible for reading and writing its own state to the database.
4.3.1 CONTAINER-MANAGED PERSISTE)
Container-managed persistence beans are the simplest for the bean developer to
create and the most difficult for the EJB server to support. This is because all the logic
for synchronizing the bean's state with the database is handled automatically by the
container. This means that the bean developer doesn't need to write any data access
logic, while the EJB server is supposed to take care of all the persistence needs
automatically -- a tall order for any vendor. Most EJB vendors support automatic
persistence to a relational database, but the level of support varies. Some provide very
sophisticated object-to-relational mapping, while others are very limited.In this panel,
you will expand the CustomerBean developed earlier to a complete definition of a
Container-managed persistence bean, In the panel on bean-managed persistence, you
will modify the CustomerBean to manage its own persistence,
4.3.2 BEAN CLASS
‘An enterprise bean is a complete component that is made up of at least two
interfaces and a bean implementation class. All these types will be presented and their
‘meaning and application explained, starting with the bean class, which is defined below:
import javax.ejb.EntityBean;
public class CustomerBean implements EntityBean {
int customerID;
Address myAddress;
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 14/22Java Beans | 2016-2018
Batch
Name myName;
CreditCard myCreditCard;
// CREATION METHODS
public Integer ejbCreate(Integer id) {
customerID = id.intValueQ);
return null;
}
public void ejbPostCreate(Integer id) {
}
public Customer ejbCreate(Integer id, Name name) {
myName = name;
return ejbCreate(id);
}
public void ejbPostCreate(Integer id, Name name) {
3
{| BUSINESS METHODS,
public Name getName() {
return myName;
}
public void setName(Name name) {
myName = name;
}
public Address getAddress() {
return myAddress;
}
public void setAddress( Address address) {
myAddress = address;
}
public CreditCard getCreditCard() {
return myCreditCard;
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 15/22Java Beans | 201
Batch
2018
3
public void setCreditCard(CreditCard card) {
myCreditCard = card;
}
{/ CALLBACK METHODS,
public void setEntityContext(EntityContext entx) {
}
public void unsetEntityContext() {
+
public void ejbLoad() {
}
public void ejbStore() {
3
public void ejbActivate() {
3
public void ejbPassivate() {
}
public void ejbRemove() {
+
}
Notice that there is no database access logic in the bean. This is because the EJB vendor
provides tools for mapping the fields in the CustomerBean to the database. The
CustomerBean class, for example, could be mapped to any database providing it contains
data that is similar to the fields in the bean. In this case, the bean's instance fields are
composed of a primitive int and simple dependent objects (Name, Address,and
CreditCard) with their own attributes Below are the definitions for these dependent
objects:
1 The Name class
public class Name implements Serializable {
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 16/22Java Beans | 201
Batch
2018
public String lastName, firstName, middleName;
public Name(String lastName, String firstName,
‘String middleName) {
this.lastName = lastName;
this. firstName = firstName;
this.middleName = middleName;
3
public Name() {}
+
II The Address class
public class Address implements Serializable {
public String street, city, state, zip;
public Address(String street, String city,
String state, String zip) {
this street = street;
tate = state;
this.zip = zip;
}
public Address() {}
,
1 The CreditCard ck
s
public class CreditCard implements Serializable {
public String number, type, name;
public Date expDate; public CreditCard(S
1g number, String type, String name, Date
expDate) {
this.number = number;
this.type = type;
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 17/22Java Beans | 201
Batch
2018
this.name = name;
this.expDate = expDate;
3
public CreditCard() {}
}
These fields are called container-managed fields because the container is responsible for
synchronizing their state with the database; the container manages the fields. Container-
‘managed fields can be any primitive data types or serializable type. This case uses both a
primitive int (customerID) and serializable objects (Address, Name, CreditCard). To map
the dependent objects to the database, a fairly sophisticated mapping tool would be
needed. Not all fields in a bean are automatically container-managed fields; some may be
just plain instance fields for the bean’s transient use. A bean developer distinguishes
container-managed fields from plain instance fields by indicating which fields are
container-managed in the deployment descriptor. The container-managed fields must
have corresponding types (columns in RDBMS) in the database either directly or through
obj
relational mapping. The CustomerBean might, for example, map to a
CUSTOMER table in the database that has the following definition:
CREATE TABLE CUSTOMER
{
id INTI
last_name CHAR(30),
first_name CHAR(20),
middle_name CHAR(20),
street CHAR(S0),
city CHAR(20),
state CHAR(2),
zip CHAR(),
credit_number CHAR(20),
EGER PRIMARY
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 18/22Java Beans | 2016-2018
Batch
credit_date DATE,
credit_name CHAR(20),
credit_type CHAR(10)
}
With container-managed persistene
the vendor must have some kind of proprietary tool
that can map the be:
specific table, CUSTOMER in this case.
container-managed fields to their corresponding columns in a
Once the bean's fields are mapped to the database, and the Customer bean is deployed,
the container will manage creating records, loading records, updating records, and
deleting records in the CUSTOMER table in response to methods invoked on the
Customer bean's remote and home interfaces.
‘A subset (one or more) of the container-managed fields will also be identified as the
bean’s primary key. The primary key is the index or pointer to a unique record(s) in the
database that makes up the state of the bean. In the case of the CustomerBean, the id field
is the primary key field and will be used to locate the bean's data in the database.
Primitive single field primary keys are represented as their corresponding object
wrappers. The primary key of the Customer bean for example is a primitive int in the
bean class, but to a bean's clients it will manifest itself as the java.lang.Integer type
Primary keys that are made up of several fields, called compound primary keys, will be
represented by a special class defined by the bean developer. Primary keys are similar in
concept to primary keys in a relational database -- actually when a relational database is
used for persistence, they are often the same thing.
).
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 19/22Java Beans | 2016-2018
Batch
4.4 MESSAGE-DRIVEN BEAN
‘A message-driven bean is an enterprise bean that allows Java EE applications to process
messages asynchronously. It normally acts as a IMS message listener, which is similar to
stead of events,
an event listener except that it receives JMS message:
The messages can be sent by any Java EE component (an application client, another
enterprise bean, or a web component) or by a JMS application or system that does not use
Java EE technology. Message-driven beans can process JMS messages or other kinds of
messages.
4.4.1 What Makes Message-Driven Beans Different from Session Beans?
‘The most visible difference between message-driven beans and session beans is that
clients do not access message-driven beans through interfaces. In several respects, a
message-driven bean resembles a stateless session bean.A message-driven bean’s
instances retain no data or conversational state for a specific client. All instances of a
message-driven bean are equivalent, allowing the EJB container to assign a message to
any message-driven bean instance. The container can pool these instances to allow
streams of messages to be processed concurrently.
A single message-driven bean can process messages from multiple clients.The instance
variables of the message-driven bean instance can contain some state across the handling
of client messages (for example, a JMS API connection, an open database connection, or
an object reference to an enterprise bean object).Client components do not locate
message-driven beans and invoke methods directly on them. Instead, a client accesses a
message-driven bean through, for example, JMS by sending messages to the message
destination for which the message-driven bean class is the Messagetistener. You assign
a message-driven bean’s destination during deployment by using Application Server
resources.
‘Message-driven beans have the following characteristies:
* They execute upon receipt ofa single client message.
+ They are invoked asynchronously.
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 20/22Java Beans | 2016-2018
Batch
© They are relatively short-lived.
* They do not represent directly shared data in the database, but they can access
and update this data.
* They can be transaction-aware.
© They are stateless.
‘When a message arrives, the container calls the message-driven bean’s ontlessage
method to process the message. The ontiessage method normally casts the message to
one of the five MS message types and handles it in accordance with the application's
business logic. The ontessage method can call helper methods, or it can invoke a s
sssion
bean to process the information in the message or to store it in a database.
‘A message can be delivered to a message-driven bean within a transaction context, so all
operations within the cntiessage method are part of a single transaction. If message
processing is rolled back, the message will be redelivered
4.4.2 when to use message-driven beans
Session beans allow you to send JMS messages and to receive them synchronously, but
not asynchronously. To avoid tying up server resources, do not to use blocking
synchronous receives in a server-side component, and in general IMS messages hould
not be sent or received synchronously. To receive messages asynchronously, use a
message-driven bean,
Example For Message Driven Bean
Example Application Overview
This application has the following components:
pleMessageClient: A J2EE application client that sends several
messages to a queue.
+ Simpleessagezup: A message-driven bean that asynchronously receives
and processes the messages that are sent to the queue.
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 21/22Java Beans | 2016-2018
Batch
Figure 4.1 illustrates the structure of this application. The application client sends
messages to the queue, which was created administratively using the
command. The JMS provider (in this, case the J2EE server) delivers the messages to the
instances of the message-driven bean, which then processes the messages.
Figure 4..1 The SimpleMessageApp Application
KEY TERMS
+ Enterprise JavaBeans: Enterprise bean implements a business task, or a
business entity.
+ EJB Server and Container: An EJB bean is said to reside within an EJB
Container that in turn resides within an EJB Server.
‘+ Deployment descriptors: The additional information required to install an EJB
within its server is provided in the deployment descriptors for that bean
‘+ The EJBObject: An instance of a generated class that implements the remote
interface defined by the bean developer
© The EJBLocalObject: An instance of a generated class that implements the local
interface defined by the bean developer
QUESTIONS
1 Mark Questions (Multiple Choice Based)
1. The method is a method that contains business logic that is
customized to the service provided by the EIB.
a. ejbActivate() —b. efbPassivate() c. ejbRemove() d, myMethodQ,
2. There are methods defined in a BMP bean,
a2 b3 4 as
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 22/22Java Beans | 2016-2018
Batch
3. InBMP bean, ‘method must contain code that reads data from a database.
a.ejbLoad() b. ejbstore) —_c. ejbCreate() d. ejbRemove()
4. The element contains subelements that describe the entity EJB.
a. b. —c. — d.
5. The subelement specifies the name of the method.
a. __b. c. _d.
6. The method is called just before the bean is available for garbage
collection.
a. ejbActivate() b. ejbPassivate() c. ejbRemove() — d. ejbCreate()
7A bean is used to model a business process.
entity b. session c. message-driven d.funetion
8. The subelement specifies the version of container-managed persistence.
a. b. c d,
9. The subelement itself has two subelements.
a. b, ¢, _d.
10. A container invokes the method to instruct the instance to
synchronize its state by loading its state from the underlying database.
a, setEntityContext() b, unsetEntityContext()
c. ejbLoadQ, d. ejbActivated,
2 Mark Questions:
1. Differentiate Java Bean and EJB
List the three different Types of EJB Classes
Define Callback Method
‘Whaat is jar file?
Define Session bean,
awhweD
Give an example for message driven bean.
8 Mark Questions:
1. Explain the Entity bean with example.
2. Describe in Detail about Session bean.
3. Illustrate Message Drive bean with suitable example
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 23/22Java Beans | 2016-2018
Batch
4, Write about EJB deployment in detail,
5. Discuss about query element and relationship element,
6. What are Enterprise Java Beans? Describe EJB interfaces
7. Write a program to build a JAVA Bean for opening an applet from JAR file
Prepared by Dr.S.Manju Priya, Department of CS, CA & IT, KAHE Page 24/22srojduosap wawkoydap
stordunsop|
wwoukoydop
soonjsoqM
ara
sosseyo erat
sureytoo gra.
xequks TWX Buysn op eu wayLM S| |
stoydiuosop|
sa08js9}01
‘poo gif aK OF
uoneayrpou noUPI soIAeYDq FIFA Jo UONEZTUOISNa a4} SazqeUd|
siojduasap yuawisoydap | _ywauskoldap ara [sosseio gra |sowewuos ara | _pue aumuru ye paeuwur ase sara soy saquiasop——____V
‘.ans0H ajOuIay at pue d2ejI2quH
stoydusosap] ——_soavyzoqut aWoT] atp BuIsn ouMUONAUA gp aI Ur swauOduI0D 1o%p9|
soutentos gra | ytowxoidap ara [sosseio gra |aowequos ara | _ pue ara am wooajaq woreorunuutuos sajpuey aug
anoge| want sainosai
uaaup-afiessour | aypjoouou | -aessour | _worssos Ainua | sige woy soRessou aataoas 0} pasn st ueaq Vv
anoge| osu
worssas | _omjoouou | -oRessour | _woyssos Aqua ssoooud ssoutsng # Jopout 01 posn st ueaq
PasHy pido qado ado Tado SUOHSOND
ALLINA
SOPSWIT! — SSVTDiaSO9T | | -souarstsiod> | |__ | | __< tourer | aurea ssey> payyrenb | _ | -asudioqa> | aquiosap yeqy siuourojagns sureyuos yuowaj) ou
| | _ | -osudiouo> wa uoU9]9 18115 24
sou] |
q s| 1 ¢ Z{_ eqn annem poureiuod are yeyp siuouuoyo ue ary,
| _ -afo> | | _ ruowsojdap ay go wiowayo yoor ayp st yuouta]9 >.
stordussop] ——saoeyzoqey ‘ara amp Koydap 01 posmbor axe yexp sayy xaqo amp qT Su0pe
sioiduosep wauXoidap | _ywouskordep ara [sassero grat [soueyuoo art | aly axryary tans ayn ut sadeysed sf anny — ou.
jusuuostaus] quouuomaug| 7
wwoumosaug] qwourdojaxsp) quaudojoaaq| uourdojanoqq
woudojanag poressanq] ——_pemnsnpuy] ——_AysBonu| _poresstonu St aI Jo worsuedxo ouy|‘ouaysysiod pofeueursoureju09|
| | ~ |-souarsysiod= [Keypads | -Arecmid | pou Aox Areuagsd amp soqurassp ——_wounayaqns au
<2w0y ‘soRpiauy ajowiar gst Ainua 40 UoIssas ayy Jo aurea
| | -te901> | __ | | -cejdsip> | -jrews> | | ref ayy ummpen aot es © saquosap — awauajoqns ou
- | | -Aiquiosse> udrojuo> | ut posn are sig Moy saquosop ——__uouuayaqns au.
sorduosop 1wawioydap|
ayn Aq pasn st pur UV
| | -Aiquiosse> |-suoo-qfo> | -asudioyua> | oro ayp jo yped ayn saquosap —______uauajaqns au.
| -Aiquiasse> |-awayo-qfo> 2 astidioqua azour 30 au0 sags uauuaaqns 24,
| | | -kedsip> | ue ansy AVE at Saquiosap ——— uawrayaqns ay
| | | -Kedsip> | auaurdojdap oxy saquiasop ——— wowayaqns 4suayja v £q poouiazajos st pun ood ayy wosy poaouioy
Careanswafe | _Qarearpale | Oarowayrale Oavwanoyala | _ st uvaq worsses ayy soAau9yA pal[e9 St porpaul au.
sjsm apd
onsesten ainqume | Atqumosse | poyour | _uonsesuen | aajoauy deur yeqy yom Jo wun we amaaxa oy sf ¥
z g + ¢ Z|_‘suonsanp ——— 0 auo sey sdiysuoneyar Areupzes ayy
+ s + ¢ q sdiysuomejar Ajeurpres yo saddy ane ary
aseqeiep|
| -pompour> | -Aronb> | __ pejuod yuouo|9 axp Jo wowa}aqns au
| -pomu> | | -poyou> up Jo aurea axp sayroads yuowiopoqns >.
-fsonb> | | -pome “snouiapoqns ona soy J]aST! waUaTaqs a4.
‘asequiep [euone|ar © woxy erep BunDayas|
-fvanb> | | -pomaur> |e Ayoads 0} sordyiasap suawdojdap e ut pasn s} |
| |-21or Aapmnoos s.r we Apisods 01 past st tiawaya ou](Oneameg) On]
Aymugnosun} awe cinuas| ad, sy wioyy pareanae st ueaq Ammua|
Oareanowafe | Oareansvale | _ Opeorale ay Sumoyqog Atarerpoura paqpea st poqour —— au
u 4 +9] s + spomjaur yoeqte> pasn <\uounuos ——— axe arayy|
‘ueaq Aunuo we ur pauteit09|
q s + ¢ Z|__Attwordts axe yexp spoyrout yo sdnoa axe aro |
anoge| evep|
niepquaysisiod | ayrjoauou | uoreuoyuy | quaistsiod erp ueag Aiua ue £q pafeurus pur poyoaiJ09 ee
anoge| ueaq uasuip] — ueaq easel] uvaq| uoneondde
rag ear Aims | a yoouou | -afessour| —uorssos | part Anus AAZE ® Jo asnoysomod amp pasaprsuod st |
0 ‘fa 200 Aq papiaoad so14s9s a4p 01 poztwoysno st yeIp a1
Opomerder | Opomopvdr |Qarourygl> | arearssegglo| Qareanoyals | _ssaursnq surewzo9 req porpaut e st powpaut 4
0
areatsseaql} ‘uonda}00 afeqred 109 a]qeyre0e|
Corowayate | arwarql2 | Qarowarale Oareanavala sy ueag ayy azojeq isnt partes st powpaut a4.
0 soaanosou as89]91 124) SSULIMO UTEILOD Pinoys pur [ood|
areatsseaql} saa{qo aq oy poumjar st weaq MOIssas op UaYpA aves assed, |
Qarearsseaqla | _Qarearpafo | Qorowayale Qareansyafa | au siamo aouesi aqp azoyoq partes st poyrou — augOvxaqwopuas|
uigafessoyyros ato w UONy ApaauIpUL poatoooy
Qaaessayyuo arowayale |_ Oras | Qodessayquo | sadessaus sasseoord ae aul azayr st poyreur —— a4
‘seqriep|
Qaxorsqfa | Oosouoyale | _Oawaxqlo | Qarorsafa | Opeotae 1801 top saxtim poous ——— ap ‘ueaq awe
-aseqevEp & UL puodar mau sHAst
Qareaigafe | Qasowayate | Qareaigafe | atowsafa | _Opeorafe | _rem apoo aney isn poau ayy “uwaq gna 0
‘oseqriep woy e1ep speay
peo gt | Qarcumyq' | Oareanal | Oatorsal | Opeorats ey) apo9 uteyuOD ysnuw poxyaut —— ___——‘ueaq dW
g s| 4 ¢ 7 twe9q AIEL Ut paUyOP spowrsu aye sou
( “jourewos geg ayy Aq 10 yaH] ayp Foy Aq sareutULIDy ANU
Oorouraae | _Oprorg!> | Ooromaygt> | joreanoyalo] Oareusseag’> qf a209q Aqorerpoun payyea st poyrou: 904,
( “seoinosai|
Jareannaye} 1 yeyp sournos urEIUOD PINoYs pu ayes ,oaIssed, |
Corarsseaqlo | _Oproral> | Qarowmya!> Coreatsseaqfa | _oup sratua aguas op 220599 parTRa st pompous! — ay.
(Oneamey) ony oseqeiep Buikropun|
Awmugnosun] awostinugias} om or Raors q areys sit aztuompoUAs op oueysur ayn FonNSt
Qaiorsqie | Oasorsals | _Opeorals ‘0 saujertoo & £q payonur st poyyaut ay.
(Onxomeg) On ‘seqniep Hui ropun|
Awmugnsun] awopcinugies| op woyy areis sy Sumpeoy Aq arms stt ozmtomqouKs oF aaueIst
Opeoqa | Qoreansyale | Opeotafs ‘yy jorunstt 0} pomyatu—— yp soyoaua soupent09 ¥yUNIT-V
JSP: What is Java Server Pages? - Evolution of Dynamic Content Technologies — JSP &
Java 2 Enterprise edition, JSP Fundamentals: Writing your first JSP- Tag conversions-
Running JSP. Programming JSP Seripts: Scripting Languages — JSP tags- JSP
directives — Scripting elements — Flow of Control — comments. Java Remote Method
Invocation,
TEXT BOOKS
1. Jim Keogh. (2010). The Complete Reference J2BE, Tata McGraw Hill: New Delhi
Ist Edition,
2. Duane, K. Fields., & Mark, A. Kolb. (2002). Web Development with Java Server
Pages, Manning Publications, Pune, 2" Edition.
REFERENCES
1. Joel Murach, Michael Urban, (2014), Murach's Java Servlets and JSP, (Murach:
Training & Reference). 3rd Edition
2. Budi Kurniawan (2012), Servlet & JSP: A Tutorial, Brainy Software Publisher, 1"
Edition.
Mahesh P. Matha (2013), JSP and SERVLETS: A Comprehensive Study PHI
Learning, 1* Edition.
WEB SITES
1. www,java.sun.com/javace!
2. www java.sun.com/j2ee/1.4/docs/tutorial/doc!
3. www j2eebrain.com/
4, www javaworld.com/
5. www.corej2eepatterns.com/
6. www jsptut.com
Prepared by Dr.S. Manju Priya, Department of CS, CA & IT, KAHE Page 1/342016-2018
Batch
5.1 WHAT IS JAVASERVER PAGES?
JavaServer Pages (JSP)
a technology for developing Webpages that supports dynamic
content. This helps developers insert java code in HTML pages by making use of special
ISP tags, most of which start with .
A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role
of a user interface for a Java web application. Web developers write ISPs as text files
that combine HTML or XHTML code, XML elements, and embedded JSP actions and
commands,
Using JSP, you can collect input from users through Webpage forms, present records
from a database or another source, and create Webpages dynamically.
JSP tags can be used for a variety of purposes, such as retrieving information from a
database or registering user preferences, accessing JavaBeans components, passing
control between pages, and sharing information between requests, pages etc.
Why Use ISP?
JavaServer Pages often serve the same purpose as programs implemented using
the Common Gateway Interface (CGI). But JSP offers several advantages in
comparison with the CGI
+ Performance is significantly better because JSP allows embedding Dynamic
Elements in HTML Pages itself instead of having separate CGI files.
+ JSP are always compiled before they are processed by the server unlike CGI/Perl
which requires the server to load an interpreter and the target script each time the
page is requested.
+ JavaServer Pages are built on top of the Java Servlets API, so like Servlets, JSP
also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI,
EJB, JAXP, etc.
Prepared by Dr.S. Manju Priya, Department of CS, CA & IT, KAHE Page 2/342016-2018
Batch
Java Server Pag
+ JSP pages can be used in combination with servlets that handle the business
logic, the model supported by Java servlet template engines.
Finally, JSP is an integral part of Java EE, a complete platform for enterprise class
applications. This means that JSP can play a part in the simplest applications to the most
complex and demanding,
Benefits of JSP
One of the main reasons why the Java Server Pages technology has evolved into what it
is today and it is still evolving is the overwhelming technical need to simplify application
design by separating dynamic content from static template display data, Another benefit
of utilizing JSP is that it allows to more cleanly separating the roles of web
application/HTML designer from a software developer. The JSP technology is blessed
with a number of exciting benefits, which are chronicled as follows:
1. The JSP technology is platform independent, in its dynamic web pages, its web
servers, and its underlying server components. That is, JSP pages perform perfectly
without any hassle on any platform, run on any web server, and web-enabled application
server. The JSP pages can be accessed from any web server
2. The JSP technology emphasizes the use of reusable components. These components
can be combined or manipulated towards developing more purposeful components and
page design. This definitely reduces development time apart from the At development
time, JSPs are very different from Servlets, however, they are precompiled into Servlets
at run time and executed by a JSP engine which is installed on a Web-enabled application
server such as BEA WebLogic and IBM WebSphere,
5.2 EVOLUTION OF DYNAMIC CONTENT TECHNOLOGIES.
Server-side scripting refers to the dynamic generation of Web pages served up by the
Web server, as opposed to "static" web pages in the server storage that are served up to
the Web browser. In other words, some part of the content sent in response to a HTTP
Prepared by Dr.S. Manju Priya, Department of CS, CA & IT, KAHE Page 3/34