Upload
doanhanh
View
228
Download
4
Embed Size (px)
Citation preview
1Huihoo - Enterprise Open Source http://www.huihoo.com
Java Web-based Programming & J2EE Architecture
Peter.Cheng Email: [email protected]
http://www.huihoo.org
2Huihoo - Enterprise Open Source http://www.huihoo.com
Course Goal
The main goal of this course is to provide you with the knowledge for Java web-based programming (JSP, Servlet, Struts), MVC Design pattern, J2EE architectures
3Huihoo - Enterprise Open Source http://www.huihoo.com
Course Overview
This course covers the following areas:
J2EE Technology overview
Web-based Programming Model
MVC Design Pattern and Struts
Framework
J2EE Architectures
Build a J2EE developer Team
4Huihoo - Enterprise Open Source http://www.huihoo.com
How To Use Course Materials
Lecture The instructor will present information specific to the topic of the module. This information will help you learn the knowledge and skills necessary to succeed with the exercises.
Exercise Lab exercises will give you the opportunity to practice your skills and apply the concepts presented in the lecture.
Think Beyond Thought-provoking questions are posed to help you apply the content of the module or predict the content in the next module.
5Huihoo - Enterprise Open Source http://www.huihoo.com
Software Architecture
OS (Unix, Windows, Linux, Mac, others)
J2EE Infrastructure(SunOne, Weblogic, Websphere, etc)
APIs, specifications
ApplicationApplication
Virtual Platform
Upper Platform
Lower Platform
6Huihoo - Enterprise Open Source http://www.huihoo.com
Architecture and the cube
Client
Presen
tation
Security
Manageability
Reliability
Availability
Scalability
Busines
s
integ
ratio
n
Application
Resou
rce
APIs, specifications
Middleware( Web, app server)
OS (Solaris, Windows, Linux ,etc)
Manageability
Security
Reliability
Availability
Scalability
Presentation
Client
Business
Integration
ResourceApplication
Virtual Platform
Upper Platform
Lower Platform
7Huihoo - Enterprise Open Source http://www.huihoo.com
Java Platform Overview
JVM JVM KVM CardVM
Java Hotspot ™ JVM Card VM
Java Programming Language
Java 2Enterprise
Edition(J2EE)Core APIs
Java 2Standard
Edition(J2SE)
Core APIs
Java 2 ME APIs
PersonalProfile
RMIProfile
Other CDC
Profiles...
FundamentalProfile MIDP
OptionalPackage
Optional Package
KVM
Java Card APIs
8Huihoo - Enterprise Open Source http://www.huihoo.com
Java is everywhere
9Huihoo - Enterprise Open Source http://www.huihoo.com
J2EE 3-Tier Architecture
Presentation
JavaApplication
JavaApplication
PureHtml
PureHtml
AppletApplet
MobileDevice
MobileDevice
J2MEJ2ME
Presentation
Web ServerWeb Server
J2EEPlatformJ2EE
Platform
JSPJSP
JavaServletJava
Servlet
Enterprise
Information
System
EISEIS
OtherSystem
OtherSystem
Business Logic
EJB ContainerEJB Container
J2EEPlatformJ2EE
Platform
EJBEJB
EJBEJB
Server Side
DesktopDesktop
JavaApplication
JavaApplication
BrowserBrowser
PureHtml
PureHtml
AppletApplet
MobileDevice
MobileDevice
J2MEJ2ME
Client Side
10Huihoo - Enterprise Open Source http://www.huihoo.com
Computing Model is changing
Model Client/Server Browser/Server
UI Application Browser (html)
Maintain Hard Easy
Couple High Lower
11Huihoo - Enterprise Open Source http://www.huihoo.com
History of Web Applications
Common Gateway Interface
Main ProcessMain ProcessChild process for CGI1Child process for CGI1
Child process for CGI2Child process for CGI2
Child process for CGI1Child process for CGI1
Request for CGI1
Request for CGI2
Request for CGI1
12Huihoo - Enterprise Open Source http://www.huihoo.com
History of Web Applications
Java Servlet
Main ProcessMain Process
JVM
Servlet1
Request for Servlet1
Servlet2
thread
thread
Request for Servlet2
Request for Servlet1
13Huihoo - Enterprise Open Source http://www.huihoo.com
Web Tier – HTTP Request/Response Model
• A Client – a web browser• Send a request for a resource to a server• Server sends back a response corresponding to the
resource
14Huihoo - Enterprise Open Source http://www.huihoo.com
The Servlet
@see HelloWorldServlet.javahttp://localhost:8081/servlet/HelloWorldServlet
15Huihoo - Enterprise Open Source http://www.huihoo.com
The Servlet – single instance
Web Server
Servlet
request
Servletrequest
request
request
@see SingleInstance.java
http://localhost:8081/servlet/SingleInstance
16Huihoo - Enterprise Open Source http://www.huihoo.com
The Servlet – Single Thread Model
Web ServerServlet PoolServlet Poolrequest
ServletInstance
ServletInstance
ServletInstance
ServletInstance
request
request
request
17Huihoo - Enterprise Open Source http://www.huihoo.com
Web Tier - What’s JSP?
JavaServer Pages ,for short—is a Java-based technology that simplifies the process of developing dynamic web sites.
A JSP page contains standard markup language elements, such as HTML tags, just like a regular web page.
A JSP page also contains special JSP elements that allow the server to insert dynamic content in the page.
18Huihoo - Enterprise Open Source http://www.huihoo.com
HTML vs. JSP
HTML
<html>
<head>
<body><LI><A>Why Use JSP</A></LI>
</body>
</html>
JSP
<html><head><body><jsp:useBean…/></body></html>
19Huihoo - Enterprise Open Source http://www.huihoo.com
Why use JSP?
Embedding Dynamic Elements in HTML Pages
CompilationCGI/Perl require the server to load an interpreter and the target script each time the page is requested.a JSP page is always compiled before it's
processed by the server.
Integration with Enterprise Java APIsJDBC, JMS, EJB, etc
20Huihoo - Enterprise Open Source http://www.huihoo.com
Inside the web server
Web container
JSP Engine
Servlet Engine
Web server
client
http request http response
Completedservlet
JSP
21Huihoo - Enterprise Open Source http://www.huihoo.com
Web Programming Model - 1
JSP(View)
Client Application
request
responseJavaBeans
(Model)JavaBeans
(Model)Data
22Huihoo - Enterprise Open Source http://www.huihoo.com
Web Programming Model - 2
Servlet(Controller)
Client Application
request
response
JavaBeans(Model)
JavaBeans(Model)
JSP(View)
Data
@see ControllerServlet.java welcome.jsp login.jsp
23Huihoo - Enterprise Open Source http://www.huihoo.com
MVC (Model-View-Controller)
Model• Encapsulates application state• Responds to state queries• Exposes application functionality• Notifies views of changes
View• Render the model• Requests model update• Send user input to controller
Controller• Define application behavior• Maps user actions to model update• Select view for response• One for each functionality
update state change
user input
view select
query model state
change notification
24Huihoo - Enterprise Open Source http://www.huihoo.com
Basic MVC Control Flow
ControllerServlet Controller ViewResolverHandlerMapping View
:getHandler(request)
Handler: Controller
:handleRequest(request, response)
:return Model And View
resolveViewname(name, local)
:return View reference
:render (model, request, response)
mapping.xml
25Huihoo - Enterprise Open Source http://www.huihoo.com
Open Source MVC Framework
Struts www.apache.org
WebWork www.opensymphony.com
Maverick http://sourceforge.net/project/mav
26Huihoo - Enterprise Open Source http://www.huihoo.com
Framework vs. Component
Framework
Application 3Extension
Application 2Extension
Application 1Extension
MainApplication
Library2
Library1
27Huihoo - Enterprise Open Source http://www.huihoo.com
Functional Application Tier
28Huihoo - Enterprise Open Source http://www.huihoo.com
The Struts framework is used within the web tier
29Huihoo - Enterprise Open Source http://www.huihoo.com
The execute() method call by controller
30Huihoo - Enterprise Open Source http://www.huihoo.com
Struts Architecture
31Huihoo - Enterprise Open Source http://www.huihoo.com
What’s J2EE Technology
Components:Application clientsAppletsWeb componentsBusiness components
ContainersManage lifecycle of business componentsProvide a federated view of J2EE APIsProvide runtime support for components
32Huihoo - Enterprise Open Source http://www.huihoo.com
J2EE Architectures
33Huihoo - Enterprise Open Source http://www.huihoo.com
J2EE Application Model
Client
Client
Client
Client
Client Enterprise Information
Systems (EIS):
Relational-Database,Legacy Applications,
ERP Systems
EJBEJB
EJBEJB
Other Services:JNDI, JMS,Java Mail
Other Services:JNDI, JMS,Java Mail
ApplicationServer
ApplicationServer
JSP/Servlet
Firewall
34Huihoo - Enterprise Open Source http://www.huihoo.com
J2EE Platform Specification
JND
I
J2SE
JMS
RM
I/IIO
P
JDB
C
DatabaseDatabase
AppClientApp
Client
App Client ContainerApp Client Container
HTTP/HTTPSHTTP/HTTPS
J2SE
RMI/IIOPRMI/IIOP
J2SE
JND
I
JMS
RM
I/IIO
P
JDB
C
JTA JavaMail
JAF JND
I
JMS
RM
I/IIO
P
JDB
C
JTA JavaMail
JAF
HTTP/HTTPSHTTP/HTTPS
Applet Container
Applet Container
AppletApplet JSPJSP ServletServlet EJBEJB
Web ContainerWeb Container EJB ContainerEJB Container
RMI/IIOPRMI/IIOP
J2SEJ2SE
35Huihoo - Enterprise Open Source http://www.huihoo.com
Vertical Scalability
Web Server
Application Server
DBMS Server
Capacity
Reliability
Availability
Manageability
Any machine leads to a system failure
36Huihoo - Enterprise Open Source http://www.huihoo.com
Horizontal Scalability
Capacity
Reliability
Web Server
Application Server DBMS
Server
Web Server
Web Server
Application Server
DBMS Server Array
Array
Availability
Manageability
37Huihoo - Enterprise Open Source http://www.huihoo.com
Design J2EE-Based Application
EJB is not the only technology for implementing the middle tier in J2EE applications
Design to Java interfaces, not concrete classes, and not technologies
38Huihoo - Enterprise Open Source http://www.huihoo.com
Non-distributed Architectures
Web Application with Business Component Interfaces
DB LegacyEIS
Middle Tier
(Business Logic)
UI Tier
Business interface
Implementation
Servlet/Web Tier classes
Web C
ontainer
J2EE Application Server
39Huihoo - Enterprise Open Source http://www.huihoo.com
Web Application that Accesses Local EJBs
DB LegacyEIS
Middle Tier
(Business Logic)
UI Tier
Business interface
Business Delegate
Servlet/Web Tier classes
Web C
ontainer
J2EE Application Server (Single JV
M)
Session Bean
Entity Bean (Optional)
Local EJB Invocation
EJB C
ontainer
40Huihoo - Enterprise Open Source http://www.huihoo.com
Distributed Architectures
DB LegacyEIS
Middle Tier
(Business Logic)
UI Tier
Business interface
Business Delegate
Servlet/Web Tier classes
Web C
ontainer
J2EE App Server
RMI Remote EJB Invocation
EJB C
ontainer
J2EE App Server
Session Bean
Entity Bean (Optional)
41Huihoo - Enterprise Open Source http://www.huihoo.com
The future of J2EE
“Service”
Couple
Small 粗糙
Tighter
loose
Transport/interfa
ce
� (Latency)
� (Bandwidth)
� (Security)
� (Transparency)� ...
42Huihoo - Enterprise Open Source http://www.huihoo.com
Service-Oriented Architecture
Network Infrastructure
WebServices
43Huihoo - Enterprise Open Source http://www.huihoo.com
New J2EE Architecture
Rich ClientsJ2EE Server: JSP/Servlet/EJB
Services
MIDP Devices
Browsers HTML/XML
XMLP/SOAPXHTML/WML
XMLP/SOAP
XMLP/SOAP
JSP
EJB
XML
JAX-RPC
JAXM
JAXB
JAXP
JDBCDBMS
JMSConnectors Existing
Apps
44Huihoo - Enterprise Open Source http://www.huihoo.com
Application Driven
45Huihoo - Enterprise Open Source http://www.huihoo.com
Service Driven
46Huihoo - Enterprise Open Source http://www.huihoo.com
Service on demand
47Huihoo - Enterprise Open Source http://www.huihoo.com
Builder a team
Markup developerThis will encompass HTML/XHTML development and possibly JavaScript.Presentation developerResponsible for more technical presentation-tier work, rather than designing good-looking HTML. Web-tier Java developerResponsible for MVC framework action classes, JSP tag handlers, and web-tier helper classes.
48Huihoo - Enterprise Open Source http://www.huihoo.com
Builder a team
Business object developerResponsible for implementing application business logic. Business object developers will use EJB where appropriate, and should have a sound understanding of EJB. Data access specialistJava developer responsible for efficient DBMS access. Often this role will be taken on by business object developers. DBASpecialist in the underlying database. DBAscan provide valuable assistance to J2EE developers in vital areas such as ensuring good performance and correct locking behavior.
49Huihoo - Enterprise Open Source http://www.huihoo.com
Exercises
Rewrite, compile, and run a program that use the JSP, Servlet
Rewrite, compile, and run a program that use the MVC design pattern
50Huihoo - Enterprise Open Source http://www.huihoo.com
Think Beyond
How to apply MVC framework to your project?
51Huihoo - Enterprise Open Source http://www.huihoo.com
Common Abbreviations and Acronyms
API - Application programming interfaceCORBA – Common Object Request Broker ArchitectureEIS – Enterprise Information SystemEJB – Enterprise JavaBeansERP – Enterprise Resource PlanningJAR – Java ArchiveJ2EE – Java 2 Platform, Enterprise EditionJMSJNDIJSPJTAJTSOMGORB
52Huihoo - Enterprise Open Source http://www.huihoo.com
Further Reading
Architecting and Design J2EE Applications SL-425 Sun Microsystems 2000
Enterprise JavaBeans Programming SL-351 SunMicrosystems 2000
Rod Johnson Expert One-on-One J2EE Design and
Development Wrox Press 2003
53Huihoo - Enterprise Open Source http://www.huihoo.com
Resources
http://java.sun.com/j2ee
http://java.sun.com/jcp
http://www.w3.org/