overview of j2ee

Upload: jayita-mukhopadhyay-bhaduri

Post on 30-May-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Overview of J2EE

    1/33

    Overview to J2EE

    By:Jayita Mukhopadhyay

  • 8/9/2019 Overview of J2EE

    2/33

    Why J2EE?

    2

    Presentation world is web-centric

    Tried other approaches

    Static HTML, CGI, Applets, ASP

    Need integration with campus-wide services

    Capitalize on developers strengths

    Programming

    Presentation DBM

    Framework is being widely adopted by vendors

  • 8/9/2019 Overview of J2EE

    3/33

    Evolution of J2EE

    Advantages of separating view from business logic and datastorage 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 managedby a container that provided common (and often complicated)runtime management for these components

    Sun marketing took Servlets+JSP+EJB+JDBC and packagedthem 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 DatabaseConnectivity (JDBC), and Remote Method Invocation (RMI)

    3

  • 8/9/2019 Overview of J2EE

    4/33

    J2EE Architecture

    4

    ExternalApplication

    Java Technologies

    ExternalApplication

    Java Technologies

  • 8/9/2019 Overview of J2EE

    5/33

    Web APIs

    5

  • 8/9/2019 Overview of J2EE

    6/33

    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

  • 8/9/2019 Overview of J2EE

    7/33

    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

  • 8/9/2019 Overview of J2EE

    8/33

    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

  • 8/9/2019 Overview of J2EE

    9/33

    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 HTTPPOST.

    POSTs are a good way to get input from HTML forms

    9

  • 8/9/2019 Overview of J2EE

    10/33

    Sample Servlet

    import java.io.*; //Apache Tomcat

    sample code

    importjavax.servlet.*;

    importjavax.servlet.http.*;

    public class HelloWorld extends HttpServlet

    {

    public void doGet(HttpServletRequest request, HttpServletResponseresponse) throws IOException,

    ServletException

    {

    response.setContentType("text/html");

    PrintWriter out = response.getWriter(); out.println("");

    out.println(""); out.println("");

    out.println("Hello World!");out.println(""); out.println("");

    out.println("Hello World!");

    out.println(""); out.println("");

    }

    }

    10

  • 8/9/2019 Overview of J2EE

    11/33

    How do Servlet Engines work?

    Server

    HTTPD

    Servlet Runner

    Servlet

    HTMLGET/POST

    Servlets can be pre-loaded (compiled by

    the VM into native code and placed intomemory) makes them as fast as native

    code

    Servlet invocation creates a new thread

    not a new instance of the servlet runner

    11

  • 8/9/2019 Overview of J2EE

    12/33

    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 aretogether 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

  • 8/9/2019 Overview of J2EE

    13/33

    Problem output from Servlets

    HTML output

    from a Servlet

    13

  • 8/9/2019 Overview of J2EE

    14/33

    JSP: Dealing with the output

    HTML output in Servlets had to be printed into the outgoingstream 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 ServerPages Invented byPaul 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 printstatements and recompile into bytecode and reload into memory ---dynamic reloading

    14

  • 8/9/2019 Overview of J2EE

    15/33

    JSP: Introduction

    Java ServerPages

    Interactive web pages

  • 8/9/2019 Overview of J2EE

    16/33

    Example JSP page

    Java code is embedded

    within the HTML

    16

  • 8/9/2019 Overview of J2EE

    17/33

    How JSP works

    HTTPD

    Servlet Runner

    Servlets

    JSP Converter

    jsp page (html+java)

    Javaservlet

    HTML

    1. HTTP-Browser requests

    JSP page

    2. Parser recognizes JSP

    extension means file

    should be given to

    JSP

    /Servlet engine ratherthan sent back to browser

    3. JSP container converts

    JSP into a java servlet

    4. Java servlet is compiled

    on the fly and given to the

    servlet runner

    5. Servlet runner loads

    servlet and executes it

    6. Output from the servlet is

    given to the HTTPD for

    return to the browser

    17

  • 8/9/2019 Overview of J2EE

    18/33

    Problems with JSP

    Java code in HTML pages difficult to read the javacode and debug

    Encourages putting display, data, logic code all

    together hard to maintain, not MVC

    Looping is difficult/error-prone

    18

  • 8/9/2019 Overview of J2EE

    19/33

    Enterprise JavaBeans (EJB)

    EJB Container:Manages security, transactions, and state management, multi-threading, resource pooling, clustering, distributed naming,automatic persistence, remote invocation, transaction boundarymanagement, and distributed transaction management

    Deals with common functionality required in business logiccomponents running on a server

    Assumes a genericclient-server framework, of which the Web isone of many

    Basically, a java server plug-in architecture where rather thanbuilding/re-building a server connection/security / clusteringcomponent, you simply create the functional modules and plug theminto such a framework already built (EJB container)

    19

  • 8/9/2019 Overview of J2EE

    20/33

    EJB

    Enterprise Java Bean

    Bean

    originally a Java class with get() and set() methods e.g.:getFirstName(), setFirstName()

    EJBs come in 3 flavors:

    20

  • 8/9/2019 Overview of J2EE

    21/33

    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 DBinteractions itself

    May be called across network connection (RMI)

    21

  • 8/9/2019 Overview of J2EE

    22/33

    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

    EJB Session Bean

    22

  • 8/9/2019 Overview of J2EE

    23/33

  • 8/9/2019 Overview of J2EE

    24/33

    When to use EJB?

    EJBs 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

  • 8/9/2019 Overview of J2EE

    25/33

    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

  • 8/9/2019 Overview of J2EE

    26/33

    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

    Programmaticfor session beans & servlets

    26

  • 8/9/2019 Overview of J2EE

    27/33

    JMS

    Java Message Service

    Point to point messaging

    each message has only one

    consumer

    used to decouple applications

    Publish/subscribe messaging

    each

    message mayh

    ave

    multiple consumers

    27

  • 8/9/2019 Overview of J2EE

    28/33

    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

  • 8/9/2019 Overview of J2EE

    29/33

    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

  • 8/9/2019 Overview of J2EE

    30/33

    Java tools forWeb Applications

    Java Servlets

    Java ServerPages (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

  • 8/9/2019 Overview of J2EE

    31/33

    J2EE Applications

    31

  • 8/9/2019 Overview of J2EE

    32/33

    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 (forapps that use databases)

    32

  • 8/9/2019 Overview of J2EE

    33/33

    THANK YOU