0% found this document useful (0 votes)
70 views33 pages

Overview To J2EE: By: Jayita Mukhopadhyay

The document provides an overview of J2EE (Java 2 Enterprise Edition). It discusses why J2EE was created, including the need for web-centric presentation, integration with campus services, and leveraging developer strengths. It describes the evolution of J2EE and key technologies like Enterprise JavaBeans (EJB), servlets, JavaServer Pages (JSP), and the J2EE architecture. EJB aims to isolate server-side logic into reusable components managed by a container. Servlets and JSPs handle web requests and generate responses but had issues that J2EE sought to address.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views33 pages

Overview To J2EE: By: Jayita Mukhopadhyay

The document provides an overview of J2EE (Java 2 Enterprise Edition). It discusses why J2EE was created, including the need for web-centric presentation, integration with campus services, and leveraging developer strengths. It describes the evolution of J2EE and key technologies like Enterprise JavaBeans (EJB), servlets, JavaServer Pages (JSP), and the J2EE architecture. EJB aims to isolate server-side logic into reusable components managed by a container. Servlets and JSPs handle web requests and generate responses but had issues that J2EE sought to address.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

Overview to J2EE

By:
Jayita Mukhopadhyay
Why J2EE?
 Presentation world is web-centric
 Tried other approaches
 Static HTML, CGI, Applets, ASP
 Need integration with campus-wide services
 Capitalize on developer’s strengths
 Programming
 Presentation
 DBM
 Framework is being widely adopted by vendors

2
Evolution of J2EE
 Advantages of separating view from business logic and data
storage became apparent (MVC Design Pattern)

 Enterprise Java Beans (EJB) introduced in 1999 as a way of


isolating server-sided logic into components that were all
managed by a container that provided common (and often
complicated) runtime management for these components

 Sun marketing took Servlets+JSP+EJB+JDBC and packaged


them together as a core “enterprise” Java Development Kit called
the Java 2 Enterprise Edition, hence the name J2EE

 Today also includes Java Messaging (JMS) API, Java Database


Connectivity (JDBC), and Remote Method Invocation (RMI)

3
J2EE Architecture

Java Technologies

External
Application

4
Web APIs

5
Initial Days Applets
Applets

 Not part of the J2EE framework


 Web-deliverable applications
 Run on client

 Problems
 Require correct JVM on client

 Difficult to write and change

 Presentation and logic combined

6
Servlets
Servlets

 Used for web applications


 Extend functionality of an HTTP server
 Replace CGIs
 Servlet support defined by specification
 Filters are part of the spec
 Consist of get and post methods for requests

7
Anatomy of a Servlet
 init() – the init() function is called when the servlet is
initialized by the server. This often happens on the first
doGet() or doPut() call of the servlet.
 destroy() – this function is called when the servlet is
being destroyed by the server, typically when the
server process is being stopped.

8
Anatomy of a Servlet
 doGet() – the doGet() function is called when the servlet is
called via an HTTP GET.
 doPost() – the doPost() function is called when the servlet
is called via an HTTP POST.
 POSTs are a good way to get input from HTML forms

9
Sample Servlet
import java.io.*; //Apache Tomcat sample code
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter(); out.println("<html>");
out.println("<body>"); out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>"); out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>"); out.println("</html>");
}
}

10
How do Servlet Engines work?

HTTPD
GET/POST HTML

HTML
T
GET or POS
Server

Servlet Runner

Servlets can be pre-loaded (compiled by Servlet


the VM into native code and placed into
memory) – makes them as fast as native
code
Servlet invocation creates a new thread
not a new instance of the servlet runner

11
Problems with Java Servlets
 Any changes to even a simple output required recompiling the
Servlet, uploading it, and restarting the Servlet engine
(disruption in service)
 All the View, Data storage/access, and Business logic are
together in multiple servlets
 Difficult to maintain over time
 jPortal has >100 servlets and all have database access and

output code intertwined!!


 Does not align well with object oriented design/UML

12
Problem output from Servlets

HTML output
from a Servlet

13
JSP: Dealing with the output
 HTML output in Servlets had to be ‘printed’ into the outgoing
stream
 Hard to maintain – any changes to the ‘look&feel’ required
programmers to change source code, recompile, stop the
server, upload the new servlet, start the server again
 Solution – Java Server Pages
 Invented by Paul Colton of LiveSoftware, first company to have a
JSP solution for its servlet container
 JSP are files that have java source code embedded within <%...
%> tags among HTML – they are specialized web pages.
 The servlet engine simply converts everything outside these
tags into output print statements on the fly
 Programmers can edit the HTML in JSPs using an HTML editor
 The JSP/servlet engine will covert the HTML lines into output print
statements and ‘recompile’ into bytecode and reload into memory ---
dynamic reloading

14
JSP: Introduction
Java Server Pages
 Interactive web pages
 <jsp:include page=“/docs/footer.html”/>
 <h2><bean:write property="pageTitle“ name="swfForm"/></h2>
 <% String tempUrl = “http://www.rpi.edu”; %>
 Extension of Servlet technology
 Similar to ASP
 Standard Tag Libraries available
 Struts:

 MVC framework

 Industry standard

 Extensible
 Can define and implement tag libraries

15
Example JSP page

Java code is embedded


within the HTML

16
How JSP works
1. HTTP-Browser requests
JSP page
2. Parser recognizes JSP
HTML extension means file
HTTPD
should be given to
jsp page (html+java) JSP/Servlet engine rather
than sent back to browser
JSP Converter 3. JSP container converts
JSP into a java servlet
4. Java servlet is compiled
Servlet Runner ‘on the fly’ and given to the
Java servlet runner
servlet 5. Servlet runner loads servlet
Servlets and executes it
6. Output from the servlet is
given to the HTTPD for
return to the browser

17
Problems with JSP
 Java code in HTML pages – difficult to read the java
code and debug

 Encourages putting display, data, logic code all


together – hard to maintain, not MVC

 Looping is difficult/error-prone

18
Enterprise JavaBeans (EJB)
 EJB Container:
“Manages security, transactions, and state management, multi-
threading, resource pooling, clustering, distributed naming,
automatic persistence, remote invocation, transaction boundary
management, and distributed transaction management”

 Deals with common functionality required in business logic


components running on a server
 Assumes a generic client-server framework, of which the Web is
one of many
 Basically, a “java server plug-in architecture” where rather than
building/re-building a server connection/security / clustering
component, you simply create the functional modules and plug
them into such a framework already built (EJB container)

19
EJB
Enterprise Java Bean

 Bean
 originally a Java class with get() and set() methods

 e.g.: getFirstName(), setFirstName()

 EJBs come in 3 flavors:

20
EJB – Entity Bean
Entity Bean

Represent actual data items (e.g. rows in a result set)

 Two forms of Entity Bean


 Container managed persistence: DB interactions handled by the
J2EE environment
 Bean managed persistence: requires that the bean carries out DB
interactions itself

 May be called across network connection (RMI)

21
EJB – Session Bean
Session Bean

 Model a process or task

 Represent resources private to the client

 May update shared data

 Two forms of Session Bean


 Stateful: state maintained between method calls

 Stateless

 One client per session bean instance

22
EJB – Message Driven Bean
Message Driven Bean
session facade
***** *
message queue

*
APPLICATION

 Used in conjunction with Java Messaging System


 Activated on JMS message arrival
 No state maintained between activations

23
When to use EJB?
 EJB’s are not required components of a web
application – web apps must be servlets, but
can be JSP, and sometimes can invoke EJBs
 EJBs are an advantage when:
 one has business logic that is easily
compartmentalized
 one needs/wants a high degree of scalability (for
example, distribute processing among multi-
machine cluster)

24
JDBC
Java DataBase Connectivity

 Java equivalent of ODBC (Open DataBase Connectivity)

 Java API that enables Java programs to execute SQL


statements. This allows Java programs to interact with
any SQL-compliant database

25
JTA
Java Transaction API
 Specifies standard interfaces between a transaction manager
(e.g. JBoss) and the parties involved in a distributed transaction
system:
 the resource manager

 the application server

 and the transactional applications

 Two types of transaction paradigm


 Declarative for entity & session beans

 Programmatic for session beans & servlets

26
JMS
Java Message Service

 Point to point messaging


 each message has only one
consumer
 used to decouple applications

 Publish/subscribe messaging
 each message may have
multiple consumers

27
JNDI
Java Naming & Directory Interface

 Provides namespace support for J2EE


 Beans located by name within container namespace

 Application attributes located by name within application local


namespace

 Controlled access from external servers

 Access to LDAP directories

28
JAAS
Java Authentication and Authorization Service

 Implements a Java version of the standard Pluggable


Authentication Module (PAM) framework

 Supports user-based authorization

 Access control at every level

29
Java tools for Web Applications
 Java Servlets
 Java Server Pages (JSP)
 Java Tag Libraries
 Jakarta Struts
 JDBC, JMS
 Enterprise Java Beans (EJB)
 JavaMail (all e-mail capabilities)
 JNDI (java naming and directory services)
 Emerging additional frameworks
 Hibernate (object-relational persistence bridge)
 AspectJ (cross cutting code insertion)

30
J2EE Applications

31
Anatomy of J2EE Web Application

 MVC designed Apps typically


include:
 View (JSPs)
 Controller (one ActionServlet)
 Model (EJB or javabeans as
needed)
 Object-relational
bridge/connection pooling (for
apps that use databases)

32
THANK YOU

You might also like