0% found this document useful (0 votes)
54 views61 pages

By Prof. Pranav Mehta, CE, IDS, NU

The document discusses Java Platform, Enterprise Edition (J2EE). It provides an overview of J2EE technologies including Java servlets, JavaServer Pages (JSP), Enterprise JavaBeans (EJB), and J2EE components. It describes how J2EE applications use containers to manage different component types like web, EJB, and application client containers. It also compares JSP to servlets, outlines advantages and disadvantages of JSP, and discusses JSP architecture approaches like page-centric and dispatcher models.

Uploaded by

Pranav J Mehta
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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views61 pages

By Prof. Pranav Mehta, CE, IDS, NU

The document discusses Java Platform, Enterprise Edition (J2EE). It provides an overview of J2EE technologies including Java servlets, JavaServer Pages (JSP), Enterprise JavaBeans (EJB), and J2EE components. It describes how J2EE applications use containers to manage different component types like web, EJB, and application client containers. It also compares JSP to servlets, outlines advantages and disadvantages of JSP, and discusses JSP architecture approaches like page-centric and dispatcher models.

Uploaded by

Pranav J Mehta
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 PDF, TXT or read online on Scribd
You are on page 1/ 61

J2EE

By Prof. Pranav Mehta, CE , IDS , NU

Introduction
Java Platform, Enterprise Edition or Java EE is a widely used platform for server programming in the Java programming language. The Java platform(Enterprise Edition) differs from the Java Standard Edition Platform (Java SE) in that It adds libraries which provide functionality to deploy fault-tolerant,distributed, multitier Java software, based largely on modular components running on an application server.
By Prof. Pranav Mehta, CE , IDS , NU

The Java 2 Platform


Platform introduced June, 1999 J2SE Java 2 Standard Edition
Java for the desktop / workstation

J2ME Java 2 Micro Edition


Java for the consumer device

J2EE - Java 2 Enterprise Edition


Java for the server

By Prof. Pranav Mehta, CE , IDS , NU

The Java 2 Platform

By Prof. Pranav Mehta, CE , IDS , NU

J2EE Technologies
Java Servlets JSP EJB JMS JDBC JNDI JTA / JTS JavaMail JAAS XML
By Prof. Pranav Mehta, CE , IDS , NU

J2EE Components

By Prof. Pranav Mehta, CE , IDS , NU

J2EE Components
J2EE applications are made up of components. Definition A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components. The J2EE specification defines the following J2EE components:
By Prof. Pranav Mehta, CE , IDS , NU

Application clients and applets are components that run on the client. Java Servlet and JavaServer Pages (JSP) technology components are web components that run on the server. Enterprise JavaBeans (EJB) components (enterprise beans) are business components that run on the server.
By Prof. Pranav Mehta, CE , IDS , NU

J2EE components are written in the Java programming language and are compiled in the same way as any program in the language. The difference between J2EE components and "standard" Java classes is that J2EE components are deployed to production, where they are run and managed by the J2EE server.
By Prof. Pranav Mehta, CE , IDS , NU

J2EE Containers
The component-based and platformindependent J2EEarchitecture makes J2EE applications easy to write because business logic is organized into reusable components In addition, the J2EE server provides underlying services in the form of a container for every component type. Containers are the interface between a component and the low-level platformspecific functionality that supports the component.
By Prof. Pranav Mehta, CE , IDS , NU

Before a Web, enterprise bean, or application client component can be executed, it must be assembled into a J2EE application and deployed into its container.

By Prof. Pranav Mehta, CE , IDS , NU

By Prof. Pranav Mehta, CE , IDS , NU

Enterprise JavaBeans (EJB) container Manages the execution of enterprise beans for J2EE applications. Enterprise beans and their container run on the J2EE server. Web container Manages the execution of JSP page and servlet components for J2EE applications. Web components and their container run on the J2EE server.
By Prof. Pranav Mehta, CE , IDS , NU

Application client container Manages the execution of application client components. Application clients and their container run on the client. Applet container Manages the execution of applets. Consists of a Web browser and Java Plug-in running on the client together
By Prof. Pranav Mehta, CE , IDS , NU

Java Server Pages


The JSP Technology Is a language for developing JSP pages, which are text based document. Java Server Pages (JSP) technology provides a simplified, fast way to create dynamic web content. JSP technology enables rapid development of web-based applications that are server- and platform-independent.
By Prof. Pranav Mehta, CE , IDS , NU

An expression language for accessing serverside objects. Can create static and dynamic web content All the dynamic capabilities of java servelet technology is provided by JSP Provides ability to access remote data via mechanism like EJB, RMI, JDBC

By Prof. Pranav Mehta, CE , IDS , NU

A JSP page is a text document that conntains two types of text Static Data : which can be expressed in any text-based format such as HTML, SVG, WML and XML JSP Element: which construct dynamic content. The file extension of the source file of JSP page is .jsp
By Prof. Pranav Mehta, CE , IDS , NU

How does JSP differs from Servlets


Servlets are pure java programs with class and method definitions whereas A JSP page is much like a text document or web page With servlets developer must write java code to output the entire markup, on the other hand a JSP page can be designed like a static web page. Servlets are well suited for handling client request and executing application logic whereas JSP pages are well suited as views.
By Prof. Pranav Mehta, CE , IDS , NU

Advantages of JSP
Code Security : It is often seen that developers look at the source code of a web page and copy the java script or other code into their own page. But this is not possible with JSP because the code written runs and remains on the server. Faster loading of page With JSP the content that the user is interested in will be dispatched to the user No extra code or content is send
By Prof. Pranav Mehta, CE , IDS , NU

No Browser Compatibility: The code written in JSP can run on any browser without any kind of compatibility issues. This is because the developer sends the standard HTML to a browser. JSP Support JSP is supported by a number of web browser. For web servers that do not support JSP and Java Servelet, add-on support is provided through JRun
By Prof. Pranav Mehta, CE , IDS , NU

Compilation: A JSP is always compiled before the web server processes it. Older technologies like CGI requires the server to load an interpreter and target the script each time the page is requested. JSP compiles each JSP page into executable code the first time it is requested and invoking the resulting code directly on all subsequent request.
By Prof. Pranav Mehta, CE , IDS , NU

JSP Element in HTML/XML: A JSP page looks a lot like a HTML or XML page. The difference about JSP compared to a regular html is that the tags are not processed by the browser instead the web server processes the JSP.

By Prof. Pranav Mehta, CE , IDS , NU

Disadvantages of JSP
Attractive Java code: Putting java code spec within a web page is a bad design One solution to this is to use a template engine. Java Code Required To do a simple task in JSP can demand putting java code in a page
By Prof. Pranav Mehta, CE , IDS , NU

JSP pages require about double the disk space to hold the page: Because JSP pages are translated into class files, the server has to store the resultant class files with the JSP pages Takes a Lot of time: JSP pages must be compiled on the server when first accessed. This initial compilation produces a noticeable delay when accessing the JSP page for the first time.
By Prof. Pranav Mehta, CE , IDS , NU

JSP vs Servlet
Servlet provides the ability to build dynamic content for websites using java and are supported by all major web servers JSP gets automatically translated into java Servlet so there is no difference between what can be done by a JSP or a servlet. Both are executed by JVM

By Prof. Pranav Mehta, CE , IDS , NU

The advantage of JSP over servlet is that the JSP allows a logical division between what is displayed and the web server side codee spec that dictates what content fills the page It is easy to modify the look and feel of what is delivered by JSP without having to alter any web server side java spec code. JSP provides the separation of applications presentation layer from its data manipulation layer
By Prof. Pranav Mehta, CE , IDS , NU

JSP vs ASP
JSP and ASP offers developers identical features. But the following are the major differences between JSP and ASP. Platform Independence: ASP are written in Vbscript or Jscript. Therefore they are not platform independent. JSP are written in Java programming language. Hence JSP is platform independent
By Prof. Pranav Mehta, CE , IDS , NU

Components: ASP use ActiveX components. JSP use Java Beans Technology as the components architecture Compilation: JSP are compiled the first time they are requested leading to faster page loading for subsequent requests, while ASP have to be translated each and every time. Thus JSP has the advantage of being faster.
By Prof. Pranav Mehta, CE , IDS , NU

Extensible JSP Tags The first difference apparent to any page author are the JSP tags themselves. While both ASP and JSP use a combination of tags and scripting to create dynamic Web pages, JSP technology enables developers to extend the JSP tags available. JSP developers can create custom tag libraries, so page authors can access more functionality using XML-like tags and depend less on scripting.
By Prof. Pranav Mehta, CE , IDS , NU

Reusability Across Platforms The JSP components (Enterprise JavaBeans, JavaBeans, or custom JSP tags) are reusable across platforms. An Enterprise JavaBean component accessing legacy databases can serve distributed systems on both UNIX and Microsoft Windows platforms.
By Prof. Pranav Mehta, CE , IDS , NU

JSP Architecture
There are two ways of using JSP technology. 1. Page-Centric or Client /server approach 2. Dispatcher or N-tier approach

By Prof. Pranav Mehta, CE , IDS , NU

Page-Centric Approach
The page-centric approach is also called Client-Server approach. The basic idea of Client-Server approach is that the application lies on the client side and services the requests connecting to the server application. JSP using this approach-processes as follows: Client makes a request.
By Prof. Pranav Mehta, CE , IDS , NU

The JSP page takes the request from client and processes it. The JSP have access to the database by using Java Beans. The requests are processed and the serviced results are sent back to client by JSP. The above approach has the advantage of simplifying the process but its disadvantage is when the number of clients increases, the process becomes difficult to handle.
By Prof. Pranav Mehta, CE , IDS , NU

By Prof. Pranav Mehta, CE , IDS , NU

Page view Architecture


This basic architecture involves direct request invocations to a server page with embedded Java code, and markup tags. Java code spec determines which content must be delivered and the HTML markup elements determines the look and feel of the content. By utilization of Servlet/ or helper beans we can seprate the application logic
By Prof. Pranav Mehta, CE , IDS , NU

This approach has many benefits. It is very easy to get started and is a low-overhead approach from a development standpoint. All of the Java code may be embedded within the HTML, so changes are confined to a limited area, reducing complexity. The figure above shows the architecture visually.
By Prof. Pranav Mehta, CE , IDS , NU

Page view with Bean Architecture


This pattern is used when java and Markup code spec architecture becomes too cluttered with business-related code and data access code. The java code spec is moved from JSP to the worker beans. Thus the JSP has a limited java code.

By Prof. Pranav Mehta, CE , IDS , NU

Request

Client
Response

JSP

Worker Beans

Business Processing

By Prof. Pranav Mehta, CE , IDS , NU

The Dispatcher Approach


In this approach, a servlet/JSP acts ac a controller, which delegates request to other JSP pages and java beans Three different architectures are commonly used with this approach Mediator-view Mediator-composite view Service to workers
By Prof. Pranav Mehta, CE , IDS , NU

In dispatcher approach the web server side application consist of multiple tires. Here the JSP interacts with the back end resources via another object or EJB components. EJB provides managed access to multiple resource, support transactions and access to underlying security mechanisms. This helps to eliminate resource sharing and performance issues of 2 tier approach.
By Prof. Pranav Mehta, CE , IDS , NU

Client

JSP/Serv elet

EJB/Bean s

EJB

Remote Object

Server

By Prof. Pranav Mehta, CE , IDS , NU

The first step in N-tired application design is identifying the correct objects and their interaction. The second step is identifying the JSPs or Servlet that will act as the front end of the web server application that interacts with the next tires.

By Prof. Pranav Mehta, CE , IDS , NU

JSP Life cycle


JSP never outputs the content directly to the browser. Instead, JSP relies on initial server-side processing process which translates JSP page into the JSP Page class. The page class then will handle all the requests made of JSP. The JSP life cycle is described as the diagram
By Prof. Pranav Mehta, CE , IDS , NU

JSP life cycle can be divided into four phases: Translation, Initialization, execution and finalization. Translation In the translation phase, JSP engine checks for the JSP syntax and translate JSP page into its page implementation class if the syntax is correct. This class is actually a standard Java servlet.
By Prof. Pranav Mehta, CE , IDS , NU

After that, JSP engine compiles the source file into class file and ready for use. If the container receives the request, it checks for the changes of the JSP page since it was last translated. If no changes was made, It just loads the servlet otherwise the process of check, translate and compile occurs again. Because the compilation process takes time so JSP engine wants to minimize it to increase the performance of the page processing.
By Prof. Pranav Mehta, CE , IDS , NU

Initialization After the translation phase, JSP engine loads the class file and create an instance of of the servlet to handle processing of the initial request. JSP engines will call a method jspInit() to initialize the a servlet. jspInit method is generated during the translation phase which is normally used for initializing applicationlevel parameters and resources.
By Prof. Pranav Mehta, CE , IDS , NU

You can also overide this method by using declaration. <%! public void jspInit(){ // put your custom code here } %>

By Prof. Pranav Mehta, CE , IDS , NU

Both the translation and compilation phases can yield errors that are only observed when the page is requested for the first time. If an error occurs while the page is being translated (for example, if the translator encounters a malformed JSP element), the server will return a ParseException, and the servlet class source file will be empty or incomplete.
By Prof. Pranav Mehta, CE , IDS , NU

If an error occurs while the JSP page is being compiled (for example, there is a syntax error in a scriptlet), the server will return a JasperException and a message that includes the name of the JSP page's servlet and the line where the error occurred.

By Prof. Pranav Mehta, CE , IDS , NU

Execution: After the initialization phase, the web container calls the method _jspService() to handle the request and returning a response to the client. Each request is handled is a separated thread. Be noted that all the scriptlets and expressions end up inside this method. The JSP directives and declaration are applied to the entire page so the are outside of this method.
By Prof. Pranav Mehta, CE , IDS , NU

Finalization In the finalization phase, the web container calls the method jspDestroy(). This method is used to clean up memory and resources. Like jspInit() method, you can override thejspDestroy() method also to do your all clean up such as release the resources you loaded in the initialization phase....
By Prof. Pranav Mehta, CE , IDS , NU

<%! public void jspDestroy(){ // put your custom code here // to clean up resources } %>

By Prof. Pranav Mehta, CE , IDS , NU

JSP Life-Cycle Step Page translation

Description < % = expression % > Translates this to a string. It is equivalent to out.print(expression);. < % yourCode % > Compiles this. Loads the JSP page's servlet class upon first request. Instantiates an instance of the servlet class. Initializes the servlet instance by calling the jspInit method. Invokes the _jspService method, passing a request and a response object. If the container needs to remove the JSP page's servlet, it calls the By Prof. Pranav Mehta, CE , IDS , NU jspDestroy method.

Page compilation

Load class
Create instance Call jspInit

Call _jspService

Call jspDestroy

JSP Life Cycle

By Prof. Pranav Mehta, CE , IDS , NU

life-cycle methods of JSP


Question: What are the life-cycle methods of JSP? Answer: Life-cycle methods of the JSP are: a) jspInit(): The container calls the jspInit() to initialize the servlet instance. It is called before any other method, and is called only once for a servlet instance. b)_jspService(): The container calls the _jspservice() for each request and it passes the request and the response objects. _jspService() method cann't be overridden.
By Prof. Pranav Mehta, CE , IDS , NU

c) jspDestroy(): The container calls this when its instance is about to destroyed. The jspInit() and jspDestroy() methods can be overridden within a JSP page

By Prof. Pranav Mehta, CE , IDS , NU

How does JSP Execute


The following happens when browser request test.jsp The browser sends its request to the web server as:
http://localhost:8080/my/test.jsp?fname=pranav This specify the value entered in the textbox as a GET parameter. The web server recognize the test.jsp file in the URL sent by the browser.
By Prof. Pranav Mehta, CE , IDS , NU

The web server recognize test.jsp by its extension and the information delivered by the browser encoded in the URL must be passed to test.jsp JSP Servlet Engine: Since the extension of request made has .jsp extension, it indicates that it is a JSP file and therefore the web server passes the request received to the JSP Servlet Engine.
By Prof. Pranav Mehta, CE , IDS , NU

Process of generating servlet: JSP files are compiled by the JSP engine into a servlet. This step creates the .jsp file as a Java servlet source file. Process of making class file: The source file from above step is compiled into a class file.

By Prof. Pranav Mehta, CE , IDS , NU

Instantiation of Servlet: The instantiation of servlet is performed using the init and service methods. In these methods, the jspInit() method is defined by the developer and the jspService method is generated by the JSP engine. Output HTML: The request received from client is executed and the output is sent as HTML.
By Prof. Pranav Mehta, CE , IDS , NU

Client Receives the Output: The Client Receives the Output and thus the result namely the HTML gets displays in the client browser.

By Prof. Pranav Mehta, CE , IDS , NU

You might also like