Top Banner
ISE 390 Dynamic Web Development Java EE Web Applications
38

ISE 390 Dynamic Web Development Java EE Web Applications.

Dec 16, 2015

Download

Documents

Austen Curran
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ISE 390 Dynamic Web Development Java EE Web Applications.

ISE 390Dynamic Web Development

Java EE

Web Applications

Page 2: ISE 390 Dynamic Web Development Java EE Web Applications.

What is a Java Web Application?

• Runs on an application server– i.e. Glassfish, Tomcat, WebSphere

• Generates interactive Web pages with:–markup code (i.e. XML, HTML)–dynamic code (i.e. JavaScript)

Page 3: ISE 390 Dynamic Web Development Java EE Web Applications.

What is JavaEE?

• Java Enterprise Edition

• Tools & APIs for eCommerce

• Front-end vs. Back-end

• Good News & Bad News

Page 4: ISE 390 Dynamic Web Development Java EE Web Applications.

JavaEE Setup is much of the battle

Page 5: ISE 390 Dynamic Web Development Java EE Web Applications.

Lots and lots of stuff

• Tools– i.e. NetBeans, Glassfish, etc.

• Core Libraries–JSF, JPA, Ajax, etc.

• Related APIs–PrimeFaces, Struts, Spring, etc.

Page 6: ISE 390 Dynamic Web Development Java EE Web Applications.

Common Java Frameworks1. Spring MVC (23%)

2. Struts 1.x (15%)

3. Apache Axis (15%)

4. Apache Xerces (14%)

5. Hibernate (12%)

6. JDOM (12%)

7. Java Applet (8.1%)

8. Apache Velocity (7.9%)

9. Apache ORO (7.0%)

10. JAX-WS (6.5%)

Source: VeraCode Bloghttp://www.veracode.com/blog/2012/01/top-ten-java-frameworks-observed-in-customer-applications/

Page 7: ISE 390 Dynamic Web Development Java EE Web Applications.

A good place to start

• Tools–NetBeans–Glassfish–MySQL–Java DB/Derby

Page 8: ISE 390 Dynamic Web Development Java EE Web Applications.

A good place to start

• Core Libraries–Java Server Faces–JSTL & EL–Java Persistance API–Enterprise Java Beans–JavaScript & Ajax

Page 9: ISE 390 Dynamic Web Development Java EE Web Applications.

A good place to start

• Related AP–RichFaces–PrimeFaces–Spring–Struts–JQuery–Google Maps API

Page 10: ISE 390 Dynamic Web Development Java EE Web Applications.

Servers, Servers, and More Servers

• What are:

– Web Servers?

– Application Servers?

– Enterprise Servers?

– Database Servers?

– Java EE Servers?

• Abstraction, abstraction, abstraction

Page 11: ISE 390 Dynamic Web Development Java EE Web Applications.

Multi-Tier JavaEE Applications

Page 12: ISE 390 Dynamic Web Development Java EE Web Applications.

JavaEE Application Communications

Page 13: ISE 390 Dynamic Web Development Java EE Web Applications.

JavaEE Servers & Containers

Page 14: ISE 390 Dynamic Web Development Java EE Web Applications.

Let's Dive into JSF• JavaServerFaces

• Start NetBeans 7.2

• Make a JSF Project

• Look at a JSF page

• What do these tags look like?

Page 15: ISE 390 Dynamic Web Development Java EE Web Applications.

Best way to find your way around• Look up every reference

• It's painfully slow, but necessary

• Unfamiliar classes:– http://docs.oracle.com/javaee/6/api/

• Unfamiliar tags:– http://docs.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/

Page 16: ISE 390 Dynamic Web Development Java EE Web Applications.

But First: Annotations

• Provide data about a program to:

– compiler

– Tools

– JVM

• Can be applied to:

– classes

– fields

– Methods

• Can contain elements with values

Page 17: ISE 390 Dynamic Web Development Java EE Web Applications.

Annotations Look-Up

• Scattered in the Java EE 6 API. Ex:– http://docs.oracle.com/javaee/6/api/javax/annotation/package-summary.html

– http://docs.oracle.com/javaee/6/api/javax/faces/bean/package-summary.html

• Via cheat sheet:– http://www.physics.usyd.edu.au/~rennie/javaEE6ReferenceSheet.pdf

Page 18: ISE 390 Dynamic Web Development Java EE Web Applications.
Page 19: ISE 390 Dynamic Web Development Java EE Web Applications.

CDI?

• Context & Dependency Injection

– f.k.a Web Beans

• Contexts?

– lets you use JavaBeans, EJBs, etc. in other contexts

• Dependency Injection?

– context polymorphism

• CDI will do much of the work behind our annotations

Page 20: ISE 390 Dynamic Web Development Java EE Web Applications.

CDI At Work

• @Named

– makes a bean accessible via a Facelet page. Ex:@Named("cart")

@SessionScoped

public class ShoppingCart

• bookcatalog.xhtml:<h:commandLink id="check" action="bookshowcart"

immediate="true"

rendered="#{cart.numberOfItems > 0}">

<h:outputText value="#{bundle.CartCheck}"/>

</h:commandLink>

Page 21: ISE 390 Dynamic Web Development Java EE Web Applications.

So what are facelets?

• A page declaration language

– used to build JSF views

• And tag libraries:

<ui: for templating

<h: for HTML components

<f: for custom actions

<c: for JSTL (Java language features)

<fn: more JSTL (Java API features)

• JSTL: JavaServerPages Standard Tag Library

Page 22: ISE 390 Dynamic Web Development Java EE Web Applications.

Facelets use EL

• Expression Language

• For what?– evaluate expressions

– get/set data

– invoke methods

• EL defines:– how to write expressions: ${customer.age + 20}

– how to reference get/set: ${customer.name}

– how to invoke methods: val="#{customer.validateName}"

Page 23: ISE 390 Dynamic Web Development Java EE Web Applications.

What's a managed bean?

• In JSF apps, typically each page connects to one. Why?– defines methods/properties associated with the page's

components

– Why?

Page 24: ISE 390 Dynamic Web Development Java EE Web Applications.

We've Seen Front-End JavaEE

• JavaServerFaces

• XHTML

• CSS

Page 25: ISE 390 Dynamic Web Development Java EE Web Applications.

Now for the Back-End

• What's the Java Persistence API (JPA)?

• What's an Enterprise Java Bean (EJB)?– server-side component

– encapsulates business logic

– Ex:

• check inventory

• order products

Page 26: ISE 390 Dynamic Web Development Java EE Web Applications.

Java Persistence API (JPA)

• Provides object/relational mapping to relational DB

• What does that mean?–makes it easy to talk to Dbs

• Why?–separate roles and employ abstraction

Page 27: ISE 390 Dynamic Web Development Java EE Web Applications.

The JPA Entity

• A JSP Domain

• It represents a DB Table–an Entity Instance would be a row

• Mapping done via annotations@Entity

public class Book

{

Page 28: ISE 390 Dynamic Web Development Java EE Web Applications.

Why use EJBs?

• Simplify development of large, distributed apps

• Scalability

• EJB Containers provide system-level services to EJBs:

– transaction management

– concurrency

– security features

• Again, separation of roles

– thinner clients

Page 29: ISE 390 Dynamic Web Development Java EE Web Applications.

Two types of EJBs

• Session EJBs

– performs a task for a client

• Message-Driven EJBs

– acts as message listener (like for JMS)

Page 30: ISE 390 Dynamic Web Development Java EE Web Applications.

Session Beans

• Clients (i.e. facelets) invoke session bean methods

• Does its work on the server

• Not persistent

– its data not saved to database

• Three Types:

– stateful, stateless, & singleton

Page 31: ISE 390 Dynamic Web Development Java EE Web Applications.

Stateful Session Beans

• Not shared

– belongs to a single client

– can store info about clients

• Lasts for duration of client/server session

– when client terminates, bean terminates

Page 32: ISE 390 Dynamic Web Development Java EE Web Applications.

Stateless Session Beans

• Support multiple clients

• Methods do not “remember” clients

• Scalability advantages over stateful beans

Page 33: ISE 390 Dynamic Web Development Java EE Web Applications.

Singleton Session Beans

• Lives for duration of application

• Only one of them

• Shared among clients

Page 34: ISE 390 Dynamic Web Development Java EE Web Applications.

Why use stateful beans?

• The bean's state represents the interaction between the bean and a specific client

• The bean needs to hold info 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 client

• Behind the scenes the bean manages the workflow of several EJBs

Page 35: ISE 390 Dynamic Web Development Java EE Web Applications.

Why use stateless beans?

• The bean has no data for a specific client

• In a single method invocation, the bean performs a generic task for all clients

• The bean implements a web service

Page 36: ISE 390 Dynamic Web Development Java EE Web Applications.

Why use singleton beans?

• State needs to be shared across the application

• A single enterprise bean needs to be accessed by multiple threads concurrently

• The application needs an enterprise bean to perform tasks upon application startup and shutdown

• The bean implements a web service

Page 37: ISE 390 Dynamic Web Development Java EE Web Applications.

How does a client use EJBs?

• Dependency injection

– i.e. @EJB

OR

• JNDI Lookup

– for non Java EE apps

Page 38: ISE 390 Dynamic Web Development Java EE Web Applications.

Today

• Go to schedule page

• Let’s do 2 tutorials together:

• Getting Started with Java EE• https://netbeans.org/kb/docs/javaee/javaee-gettingstarted.html

• Creating an Enterprise EJB App• https://netbeans.org/kb/docs/javaee/javaee-entapp-ejb.html