Java Unit 1
Java Unit 1
UNIT I
CHAPTER
Understanding Java 2 EE
and Servlet
Syllabus
Understanding Java EE : What is an Enterprise Application? What is java enterprise
edition? Java EE Technologies, Java EE evolution, Glass fish sever.
Java EE Architecture, Server and Containers : Types of Systerm Architecture, Java
EE Server, Java EE Containers.
Introduction to Java Servlets: The Need for Dynamic Content, Java Servlet
Technology, Why Servlets ? What can Servlets do?
Serviet API and Lifecycle : Java Servlet API, The Servlet Skeleton, The Servlet Life
Cycle, A Simple Welcome Serviet.
Working With Servlets : Getting Started, Using Annotations Instead of Deployment
Descriptor.
Working with Databases : What Is JDBC? JDBC Architecture, Accessing
Database,
The Serviet GUl and Database Example.
Understanding Java 2 EE E
Enterprise Java (MU B.Sc. IT- Sem-V) 1-2
interoperability.
Timely development and deployment.
Edition?
Syllabus Topic:What is Java Enterprise
i.1.2 What is Java Enterprise Edition?
J2EE defines the standard for developing multitier enterprise applications.
It stands for Java 2 Platform Enterprise Edition.
Sun/Oracle f
J2EE is a platform-independent, Java-centric environment from
developing, building and deploying Web-based enterprise applications online.
The J2EE platform consists of a set of services, APIs, and protocols that provide tt
functionality for developing multi-tiered, Web-based applications.
It simplifies enterprise applications by :
Standardized modular components.
Providing a complete set of services to those modular components.
Automatically handling many details of application behavior without compler
programming.
:
Syllabus Topic Java EE Technologies
Enterprise Java (MU B.Sc. IT - Sem-V) 1-3 Understanding Java 2 EE& Serviet
Browsers
Fig. 1.2.1: Client/Server Architecture Servlet JSP Page
EIS-tier
cost
Lower deployment and maintenance 2) Web container
Concurrency
1.2.2 Java EE Server Availability
The runtime portion of aJava EE product. A Java EE server provides EJB and wel Lifecycle Management
as
Contaipners. The container also manages non-configurable services such
Underetanding Java
1-8 28E&B
Enterprise Java (MU B.SC. IT- Som-V).
E Need for Dynamlc Dordot
Servlots and The
B
Servlct.
crentes
threadh
, Servlet technolopy is uned to create a wch application (ressdes at server side and
Advantagos of Servlot
Syllabuo Toplc What can Serviste do?
:
Bettor performanc0
What can Sorviets do?
1.
1.3.4
to cxtcnd the capabilitics of
servlet is a Java programming languaye class that uscd
2. Portability is
A
thterataNting Java ke
Sorvehatext
Le's seo tho sheleton stuci hatmt bo ollowd towte ihe servlet.
Web ap)
(Context-Roo)
13, ServletRequesaAltributelistener
WelrINF
13, Servleontexthistenr
(lases in javax,servlet package : Clasaos
They are as follows
ane mny clasNCS in javav.servlet pakage,
her ServdetluputStream cluan titaa
1. GenerieServlet
ServletRequestWraper Wb xnl
3. ServleOulutSteam HTML
ServletRequestivent
$. ServleResponse\Wraprr
ote.)
ServletRequestAributelivent Static Resourcos (og. lmajos,C99
7. SenvletContextvent
Sorvletixception Fig. 14.1:Skeleton Structure
9, ServlerContextAttributeEvent 0.
Llto Cycle
Syllabus Toplc Tho Sorvlet
:
II. UnavailableExeepion
Interfaces in javas.servlet.http package Tho Sorvlot Lito Cycle
are as follows
:
1.4.3
javax,servlet.httn package, Thèy
There are many interfaces in
HupServletResponse The Init() Method invoked by the weh
2. nnethod of servlet und
I. HupServletRequcst Initializes the servlet.
It is the life cycle
HupSessionlistener once.
HtpSession containcr only
6. HupSessionBindingListener
HtpSessionAttributeListener Syntax
5.
8. HtpSessionContext (deprecated now) ServletException
7. HtpSessionActivationListener publie vokl iit() throNs
Understanding Java
1-14 2EE
-
B.Sc. IT Sem-V)
Enterprise Java (MU
IT - Sem-V) Understanding Java 2 EE & Servlet
Getting Started Enterprise Java (MU B.Sc. 1-15
Syllabus Topic:
response.setContentlype('text/html");
protected void doGet(HtpServletRequest recjiest, HipServletlesponse response) 4. 100% Pure Java (Thin
Driver)
Aoirzicrn
Ciet Waire
Fie 63:Ktre
M
árive
Disatertage
KEtages
Catatas
Foicatr
<br>
2
EE & S
Understanding Java
1-18 Understanding Java 2 EE & Servlet
B.SC. IT- Sem-V) Enterprise Java (MU B.Sc.IT- Sem-V) 1-19
Enterprise Java (MU
a
to the data source. This requires
the two-tier model, Java application talks directly
a
In
Advantage can perform man source being accessed.
application server that JDBC driver that can communicate with the particular data
library is required because of
No client side database or other data sourcc, and the results of
A user's commands arc delivered
to the
balancing, logging ctc.
tasks like auditing, load user.
those statements are sent back to the
a
may on another machine to which the user is connected via
Disadvantages The data source be located
as the
a configuration, with the user's machine
on client machine. network. This is referrcd to as clienUserver
Network support is required source as the server.
middle tier. client, and the machine housing the data
coding to be done in the
Requires database-spccific Java Application Client Machine
requires dataha
becomes costly because it The network can be an intranet, which, for
Maintenance of Network Protocol driver a JDBC
in the middle tier. example, connects employees within
specific coding to be done DBMS-proprietary protocol
Driver) corporation, or it can be the Internet.
Type 4: 100% Pure Java (Thin are sent
driver communicates directly with
the vendo. In the three-tier model, commands Database server
In a Type 4 driver,
a pure Java-based DBMS
performance driver available for th. to a "middle tier" of services, which then
is the highest
database through socket connection. This source. Fig. 1.6.6: Two-tier Architecture for
vendor itself. sends the commands to the data
database and is usually provided by the Data Access
tier.
and sends the results back to the middle
The data source processes the commands very attractive
Jdbc API user. directors find the three-tier model
which then sends them to the MIS
to maintain control over access and the kinds of
because the middle tier makes it possible
updates that can be made to corporate data.
Database many
of applications. Finally, in
Java Thin driver Another advantage is that it simplifies the deployment
Application
cases, the three-tier architecture can provide performance advantages.
Client Machine
Java applet or Client Machine (GUI)
HTML browser
Dlsadvantáge:
Database server
Drivers depend on the Database DBMS
1.6.3 JDBC Architecture The JDBC API is comprised of two Java packages OR (NIC
IGA
The JDBC API supports both two-tier and threc-tier processing java.sq!
models for database
access. javax.sql.
<br>
The Statement interface provides methods to execute queries with the database.
The statement interface is a factory of ResultSet i.e. it provides factory method to get the
object of ResultSet. Projects n Fles Services
Practca_1C
Web Pages
Syllabus Toplc: Accessing Database
E- Sorce Padages
1.6.4 Accessing Database <defait padage>
Enterprise Java (MU B.Sc. IT- SomV) 1-23 Undorstanding Java 2 EE & Servlot
Rkrsadelmxulesketumysql-conncctor-java-S. I.23.:
Adi jar tilk ehan PreparedStatenment pst conpreparmstatenent("ineert into user values(?.?2,2)"):
index.htm! pat.aetString(l.id):
<htm> pst.setString(2,p*):
<head> pat.setString(3,em):
Sizle>Registrstiet Pute<ite> pst.setString(4.co):
<hesd> int row pst.executelUplate(0:
<hdy>
Khrm ation RegisterSevlet
= > oul.println("<hl>"+ow+" Iuserted Suecesfullyyyyy"):
<HISWleene to Registration pg<Hl>
Eter t'set Name <input type='text" name="txtUid"> <br> catch(Exception e)