• No results found

CS Developing Web Applications with Java Technologies

N/A
N/A
Protected

Academic year: 2021

Share "CS Developing Web Applications with Java Technologies"

Copied!
58
0
0

Loading.... (view fulltext now)

Full text

(1)

CS 55.17

Developing Web Applications

with

(2)

Class Introduction

● Instructor: David B. Pearson

● Email: [email protected] ● Yahoo! ID: DavidPearson

(3)

About David

● I make my living developing web applications

using Java technology.

● I've been working with Java since 1997.

● I've been teaching Java since 2002.

● I am a Sun Certified Java Programmer

● I have also taught Java Programming, PHP

Programming, HTML, Introduction to the Apache Web Server

(4)

Goal

The purpose of this course is to learn to develop web applications using several Java

technologies. The skill and knowledge required to write web applications will be developed.

(5)

Objectives

● Understand the rational of the Java servlet

specification.

● Employ object-oriented design methods.

● Work within an integrated development

environment.

(6)

Prerequisites

● Previous programming experience with Java

(7)

Lecture

● 3 Hour Lecture in Room 2913 and online via

Elluminate

● 6:30 – 9:30 PM

(8)

Text Books

● Core Servlets and JavaServer Pages: Core

Technologies, Vol. 1 (2nd Edition) by Marty Hall

● More Servlets and JavaServer Pages (1st

Edition) by Marty Hall

● The Java EE 6 Tutorial

(9)

Class Website

(10)

What is JEE?

● Java Enterprise Edition

● Open standards based platform for

application:

– Development – Deployment – Management

(11)

Java Editions

Java Technology

Enabled Devices Java Technology

(12)

Tiered Enterprise Applications

● Single Tier

● Two Tier

● Three Tier

(13)

Components of Enterprise

Applications

● Things that make up an enterprise application

– Presentation logic – Business logic

– Data access logic (and data model) – System services

● The evolution of enterprise application

framework reflects

– How flexibly you want to make changes

(14)

Single Tier

● Typically mainframe-based

● Dumb terminals are directly connected to the

computer

● Centralized model

● Presentation, business logic and data access

(15)

Single Tier: Pros & Cons

● Pros:

– No client side management is required – Data consistency is easy to achieve

● Cons:

– Functionality (presentation, data model,

business logic) is intertwined, difficult for updates and maintenance and code reuse

(16)

Two Tier

● Fat clients talking to back end database

– SQL queries sent, raw data returned

● Presentation, Business logic and Data Model

processing logic in the client application

Database

Database

SQL request

(17)

Two-Tier: Pros & Cons

● Pros:

– Database product independence

● Cons:

– Presentation,data model, business logic are

intertwined at the client side, difficult for updates and maintenance

– Data Model is “tightly coupled” to every client: if DB

Schema changes, all clients break

– Updates have to be deployed to all clients making

system maintenance nightmare

– DB connection for every client, the difficult to scale – Raw data transferred to client for processing causes

(18)

Three-Tier (RPC based)

● Thinner client: business & data model

separated from presentation

– Business logic and data access logic reside in

middle tier while client handles presentation

● Middle tier server is required to handle system

services

– Concurrency control, threading, transaction,

security, persistence, multiplexing, performance, etc. Database RPC request RPC response SQL request SQL response

(19)

Three-Tier (RPC based): Pros &

Cons

● Pros:

– Business logic can change more flexibly than

2-tier model

● Most business logic resides in the

middle-tier server

● Cons:

– Complexity is introduced in the middle-tier server – Client and middle-tier server is more tightly

coupled (than the three-tier object based model)

– Code is not really reusable (compared to object

(20)

Three-Tier (Remote Object based)

● Business logic and data model captured in

object

– Business logic and database are now

described in “abstraction” (interface language)

● Object models used: CORBA, RMI, DCOM

– Interface language in CORBA is IDL

– Interface language in RMI is Java interface

Database

Object request

Object response

SQL request

(21)

Three-Tier (Remote Object based):

Pros & Cons

● Pros:

– More loosely coupled than RPC model – Code could be more reusable

● Cons:

– Complexity in the middle-tier still needs to be

(22)

Three-Tier (Web Server)

● Browser handles presentation logic

● Browser talks to web server via HTTP protocol

● Business logic and data model are handles by

“dynamic content generation” technologies (CGI, Servlet/JSP, ASP)

Database Web Server HTML request HTML response SQL request SQL response

(23)

Three-Tier (Web Server based):

Pros & Cons

● Pros:

– Ubiquitous client types – Zero client management

– Support various client devices

● Cons:

– Complexity in the middle-tier still needs to be

(24)

Trends

● Moving from single-tier or two-tier to multi-tier

architecture

● Moving from monolithic model to object-based

application model

● Moving from application-based client to

(25)

Single-tier vs. Multi-tier

● Single-tier – No separation among presentation, business logic, database – Hard to maintain ● Multi-tier – Separation among presentation, business logic, database – More flexible to change, i.e. presentation can change without affecting other tiers

(26)

Monolithic vs. Object-based

● Monolithic – 1 binary file – Recompiled, relinked, redeployed

every time there is a change

● Object-based

– Pluggable parts – Reusable

– Enables better design – Easier update – Implementation can be separated from interface – Only interface is published

(27)

Outstanding Issues & Solutions

● Complexity at the middle tier still remains

● Duplicate system services still needs to be

provided for the majority of enterprise applications

– Concurrency control, transactions – Load-balancing, Security

– Resource management, Connection pooling

● How to solve this problem?

– Commonly shared container that handles the

above system services

(28)

Proprietary Solution

● Use “component and container” model

– Components capture business logic – Container provides system services

● The contract between components and

container is defined in a well-defined but with proprietary manner

● Problem of proprietary solution: vendor lock-in

(29)

Open and Standard Solution

● Use “component and container” model in

which container provides system services in a well-defined and as industry standard

● JEE is that standard that also provides

portability of code because it is base on Java technology and standard-based Java

(30)
(31)

Platform Value to Developers

● Can use any JEE implementation for

development and deployment

– Use production-quality standard implementation

which is free for development/deployment

– Use high-end commercial JEE products for

scalability and fault-tolerance

● Vast amount of JEE community resources

– Many JEE related books, articles, tutorials, quality

code you can use, best practice guidelines, design patterns, etc.

● Can use off-the-shelf 3rd-party business

(32)

Platform Value to Vendors

● Vendors work together on specifications and

then compete in implementations

– In the areas of Scalability, Performance,

Reliability, Availability, Management and development tools, and so on.

● Freedom to innovate while maintaining the

portability of applications

● Do not have create/maintain their own

(33)

Platform Value to Business

Customers

● Application portability

● Many implementation choices are possible

based on various requirements

– Price (free to high-end), scalability (single CPU

to clustered model), reliability, performance, tools, and more

– Best of breed applications and platforms

(34)

Tiered Java Applications

● The Client Tier

● The Web Tier

● The Business Tier

(35)

The Web Tier

● Primary focus of this class

● Technology

– Servlets

– JavaServer Pages

– Expression Lanaguage

– JavaServer Pages Standard Tag Library – JavaBeans Components

– JavaServer Faces

(36)

The Business Tier

● Provides the functionality to a particular

business domain

● Technologies

– Enterprise JavaBeans – Web services

(37)

The Enterprise Information Systems

Tier

● Typically located on a different machine than

the Java EE application server

● Technologies

– Java Database Connectivity API (JDBC) – Java Persistence API

– Java EE Connector Architecture – Java Transaction API (JTA)

(38)

Java EE Servers

● A server application that implements the Java

EE platform APIs and provides the standard Java EE services.

● Composed of “Containers”

– The Web Container

– The Application Client Container – The EJB Container

(39)

JEE Summary

● JEE is the platform of choice for development

and deployment of n-tier, web-based,

transactional, component-based enterprise applications

● JEE is standard-based architecture

● JEE is all about community

● JEE evolves according to the needs of the

(40)
(41)

What is a Servlet?

● Java object which extends the functionality of

a HTTP server

● Dynamic content generation

● Better alternative to CGI, NSAPI, ISAPI, etc.

– Efficient

– Platform and server independent – Session management

(42)

Servlet vs. CGI

Request Servlet 1 Request CGI 2 Request CGI 3 CGI Based Webserver

Child for CGI 1

Child for CGI 2

Child for CGI 3

Servlet Based WebServer

Servlet 1 Servlet 2 JVM Servlet 1 Request CGI 1 Request Servlet 2 Request Servlet 3

(43)

A Servlet's Job

● Read explicit data sent by client (form data)

● Read implicit data sent by client (request

headers)

● Generate the results

● Send the explicit data back to client (HTML)

● Send the implicit data to client (status codes

(44)

HTTP Headers

● In a request, HTTP sends hidden data from

the browser to the web server, and then it sends what the user is transmitting, this

hidden data, because the data comes first, it is call HTTP Headers

● In a response, HTTP sends hidden data from

the web server to the browser, before it sends the data that gets displayed in the browser

(45)

Why build web pages dynamically?

● The Web page is based on data submitted by

the user

– E.g., results page from search engines and

order-confirmation pages at on-line stores

● The Web page is derived from data that

changes frequently

– E.g., a weather report or news headlines page

● The Web page uses information from

databases or other server-side sources

– E.g., an e-commerce site could use a servlet to build a

Web page that lists the current price and availability of each item that is for sale.

(46)

What is JSP technology?

● Enables separation of business logic from

presentation

– Presentation is in the form of HTML or XML

– Business logic is implemented as Java Beans

or custom tags

– Better maintainability, reusability

● Extensible via custom tags

(47)

The Power of JSP

● Idea

– Use regular HTML for most of page

– Mark dynamic content with special tags

<!DOCTYPE html> <html>

<head><title>Welcome to Our Store</title></head> <body>

<h1>Welcome to Our Store</h1> <p>Welcome,

<!-- User name is "New User" for first-time visitors --> <%= coreservlets.Utils.getUserNameFromCookie(request) %>

<%= coreservlets.Utils.getUserNameFromCookie(request) %>

To access your account settings, click

<a href="Account-Settings.html">here.</a></p>

<p>Regular HTML for rest of on-line store’s Web page</p> </body>

(48)

Online Documentation

● Servlets and JSP

– http://download.oracle.com/javaee/6/api/

● Java 6

(49)
(50)

Installing Java SE 6

● Minimum Java version

– Tomcat 7 (Servlet 3.0) requires Java 6

● Downloading and installation

– Follow directions at

http://download.oracle.com/javase/

● Choose “JDK” not “JRE”

– Not “with Java EE”, “with JavaFX”, or “with

(51)

Download and Unzip tomcat

● Start at http://tomcat.apache.org/

– Choose download link on left, then ZIP version

● Tomcat 7

● Just unzip the file

(52)

Installing Eclipse

● Eclipse is a free open source IDE for Java,

HTML, CSS, JavaScript, PHP, C++, and more.

– http://www.eclipse.org/downloads/

– Choose “Eclipse IDE for Java EE Developers”

● Need version 3.6 (Helios) or better for Tomcat 7

(53)

Configure Eclipse

● Tell Eclipse about Java version

– Window → Preferences → Java → Installed JREs →

Press “Add”, choose “Standard VM”, navigate to JDK folder (not bin subdirectory)

● i.e. C:\Program Files\Java\jdk1.7.0

● Tell Eclipse about Tomcat

– Click on Severs tab at bottom. Right-click in window. – New → Sever → Apache → Tomcat 7.0 → Next →

navigate to folder → Finish

● Suppress serializable warnings

– Window → Preferences → Java → Compiler →

(54)
(55)

Making Web Apps in Eclipse

● Make empty project

– File → New → Project → Web → Dynamic

Web Project

– For “Target runtime” choose “Apache Tomcat

v7.0”

– Give it a name → A01_Lastname_Firstname – Accept all other defaults

(56)

Adding Code to Eclipse Projects

● Locations

– Java Resources: src

● Servlet code

– WebContent

● Web files (HTML, JavaScript, CSS, JSP, images,

etc.)

– WebContent/some-subdirectory

● Web content in subdirectory

– WebContent/WEB-INF

● web.xml

– Optional with servlets 3.0. required in 2.5 & earlier – Will be discussed later

(57)

Testing New App

● Deploy project

– Select “Servers” tab at bottom – Right-click on Tomcat

– Choose “Add and Remove” – Choose project

– Press “Add” – Click “Finish”

● Start Server

– Right-click Tomcat at bottom

– Restart (use “Start” if Tomcat not already running)

● Test URL

(58)

Homework

● Read

● Install software

References

Related documents

IFor a faster close, Murphy Business Associates can prepare a professional third-party valuation to determine your company’s fair market value.. This will ensure that your

Objectives The purpose of this study was to evaluate if positron emission tomography (PET)/magnetic resonance imaging (MRI) with just one gradient echo sequence using the body coil

Range Scenario 1: Defense Industrial Base (DIB) Attack (EternalBlue) Range Scenario 2: DoD Network Attack (VLC Arbitrary Code Execution) Range Scenario 3: DoD Network Attack

Ambos os grupos foram avaliados com os testes de Fala com Ruído, Escuta com Dígitos, e questionário de auto- avaliação Abbreviated Profile of Hearing Aid Benefit (APHAB), em

Wearing of suitable protect- ive equipment (including personal protective equipment referred to under Section 8 of the safety data sheet) to pre- vent any contamination of skin,

[r]

In line with studies about language ideology (Woolard &amp; Schieffelin, 1994), teachers use Hebrew to foster Jewish identity addressing their students as a group, as part of

Presentación de modificaciones a la Guía para la confección de las notas a los Estados Financieros Consolidados del Sector Gobierno a nivel Municipal para el cuarto trimestre y