34
1 Build a Web Build a Web Application on J2EE Application on J2EE

Build a Web Application on J2EE

  • Upload
    luisa

  • View
    20

  • Download
    0

Embed Size (px)

DESCRIPTION

Build a Web Application on J2EE. J2EE Scenario. Client – Web Server – EIS Resources Client – Application Server – EIS Resources Client – Web Server – Application Server – EIS Resources. Client – Web Server – EIS Resources. Business to Business. Web Application. - PowerPoint PPT Presentation

Citation preview

Page 1: Build a Web Application on J2EE

11

Build a Web Application on Build a Web Application on J2EEJ2EE

Page 2: Build a Web Application on J2EE

22

J2EE Scenario

Client – Web Server – EIS ResourcesClient – Web Server – EIS Resources

Client – Application Server – EIS Client – Application Server – EIS ResourcesResources

Client – Web Server – Application Client – Web Server – Application Server – EIS ResourcesServer – EIS Resources

Page 3: Build a Web Application on J2EE

33

Client – Web Server – EIS Client – Web Server – EIS ResourcesResources

C lien t D ataB asee

S erv let

JS P

X M L

JD B C

H T M LH T T PX M L

Page 4: Build a Web Application on J2EE

44

Business to BusinessBusiness to Business

S tan d -a lo n eC lin e t

B ro w ser

Java S e rver

L egacyS ys tem

D atab ase

D istr ib u teC O R B AO b je c t

J N D I

R M I

J M S

JD B C

JA V A ID L

S erv let

JS P

Page 5: Build a Web Application on J2EE

55

Web ApplicationWeb Application

A web application is a collection of servlets, A web application is a collection of servlets, html pages, classes, and other resources html pages, classes, and other resources that can be bundled and run on multiple that can be bundled and run on multiple containers from multiple vendors.containers from multiple vendors.

A Web application is located on a central A Web application is located on a central server and provides service to a variety of server and provides service to a variety of clients.clients.

Web applications provide dynamic and Web applications provide dynamic and interactive content to browser-based clients.interactive content to browser-based clients.

Page 6: Build a Web Application on J2EE

66

Web Application Web Application EnvironmentEnvironment

W ebC on tain er

B ro w s e rA p p lic a tio nC o n ta in e r

D a ta b a s e

E I S

D is tr ibu teC O R B AO bje c ts

J D K

O p e ra tio n S ys te m

Page 7: Build a Web Application on J2EE

77

JDKJDK

All J2EE applications require the Java All J2EE applications require the Java Developers Kit to run Java classes or the Developers Kit to run Java classes or the Java Virtual Machine (JVM). Java Virtual Machine (JVM).

Download JDK from java.sun.com for freeDownload JDK from java.sun.com for free

Configure several environment variables.Configure several environment variables. JAVA_HOMEJAVA_HOME CLASSPATHCLASSPATH

Page 8: Build a Web Application on J2EE

88

Web Application StructureWeb Application Structure

J S PS erv lets

B ro w s e r

E J BJ a v a C la s s e s

D a ta b a s e

E I S

D i s tr i buteC O R B AO b j e c t s

J D B C

J ND I

R M I..

W e bC o n ta in e r

C o n n e cto r

A pplica t io n C o n ta in e r

Page 9: Build a Web Application on J2EE

99

ContainerContainer

The container is an independent The container is an independent application that creates an application that creates an environment for web components. environment for web components.

Page 10: Build a Web Application on J2EE

1010

Functions of ContainerFunctions of Container

Life cycle management for Life cycle management for components. components.

Environment configuration. Environment configuration.

Resources. Resources.

Page 11: Build a Web Application on J2EE

1111

Web ContainerWeb Container

An entity that implements the Web component An entity that implements the Web component contract of the J2EE architecture.contract of the J2EE architecture.

specify a runtime environment for Web specify a runtime environment for Web components that includes security, concurrency, components that includes security, concurrency, life cycle management, transaction, deployment, life cycle management, transaction, deployment, and other servicesand other services

provide the same services as a JSP container and provide the same services as a JSP container and a federated view of the J2EE platform APIs. a federated view of the J2EE platform APIs.

can run a Web application that is tagged as can run a Web application that is tagged as distributable and that executes across multiple distributable and that executes across multiple Java virtual machines running on the same host Java virtual machines running on the same host or on different hosts.or on different hosts.

Page 12: Build a Web Application on J2EE

1212

Web Container ProviderWeb Container Provider

Open SourceOpen Source TomcatTomcat …… ……

Business ProductBusiness Product WebLogic WebLogic WebShpereWebShpere …… ……

Page 13: Build a Web Application on J2EE

1313

TomcatTomcat

Just a JSP, Servlets ContainerJust a JSP, Servlets Container

jakarta.apache.org/tomcat/jakarta.apache.org/tomcat/index.html index.html

Page 14: Build a Web Application on J2EE

1414

Application ContainerApplication Container

An entity that implements the Java Classes An entity that implements the Java Classes contract of the J2EE architecture.contract of the J2EE architecture.

Java Classes include:Java Classes include: EJBEJB other Java Classesother Java Classes

access to the J2EE service and access to the J2EE service and communication APIs.communication APIs.

Page 15: Build a Web Application on J2EE

1515

Application Container Application Container ProviderProvider

Open SourceOpen Source JBOSSJBOSS …… ……

Business ProductBusiness Product WebLogic WebLogic WebShpereWebShpere SilverstreamSilverstream …… ……

Page 16: Build a Web Application on J2EE

1616

ConnectorsConnectors

The connector is where the abstract really The connector is where the abstract really meets the concrete. meets the concrete.

A connector is a translator between an A connector is a translator between an enterprise information system and the enterprise information system and the J2EE interfaces. J2EE interfaces.

Another type of connector, a JNDI Service Another type of connector, a JNDI Service Provider Interface, provides access to Provider Interface, provides access to naming and directory services. naming and directory services.

Page 17: Build a Web Application on J2EE

1717

JDBCJDBC

a JDBC driver, provides access to a JDBC driver, provides access to databases.databases.

Page 18: Build a Web Application on J2EE

1818

JNDIJNDI

provides access to naming and directory servicesprovides access to naming and directory services

provides a link between Java code and various provides a link between Java code and various naming and directory services such as Domain naming and directory services such as Domain Name System (DNS), Novell Directory Service Name System (DNS), Novell Directory Service (NDS), CORBA, and Network Information System (NDS), CORBA, and Network Information System (NIS).(NIS).

allows you to access code and resources across allows you to access code and resources across widely separated platforms and directory widely separated platforms and directory structures through the use of a simple naming structures through the use of a simple naming scheme. scheme.

Page 19: Build a Web Application on J2EE

1919

ToolsTools

AntAnt

IDEIDE

JbuilderJbuilder

NetBeansNetBeans

Page 20: Build a Web Application on J2EE

2020

Data format used in Web Data format used in Web ApplicationApplication

HTML HTML JSPJSP Image filesImage files GifGif JPEGJPEG Class fileClass file Source codeSource code Complied codeComplied code XMLXML JAR file: used in J2EE for packaging EJBs and client-JAR file: used in J2EE for packaging EJBs and client-

side Java Applicationsside Java Applications WAR file: web applications made from Servlets, WAR file: web applications made from Servlets,

JSPs, and supporting classesJSPs, and supporting classes EAR file: contain all of the components that make EAR file: contain all of the components that make

up a particular J2EE applicationup a particular J2EE application

Page 21: Build a Web Application on J2EE

2121

Web Application can be Web Application can be exist in exist in

WAR filesWAR files

directorydirectory

Page 22: Build a Web Application on J2EE

2222

Web Application Archive Web Application Archive FileFile

Web applications can be packaged and Web applications can be packaged and signed, using the standard Java Archive signed, using the standard Java Archive tools, into a Web ARchive format (war) file. tools, into a Web ARchive format (war) file.

When packaged into such a form, a META-When packaged into such a form, a META-INF directory will be present which INF directory will be present which contains information useful to the Java contains information useful to the Java Archive tools. Archive tools.

Page 23: Build a Web Application on J2EE

2323

Basic Web Application Basic Web Application Directory Directory

W eb A p p / (W eb A p p lication R oot F old er)

Inde x.H T M L

Inde x.J S P

W E B _ IN F /

W E B .X M L

C la s s e s /

L ib /

Page 24: Build a Web Application on J2EE

2424

Root Root

The root of this hierarchy serves as a The root of this hierarchy serves as a document root for serving files that are document root for serving files that are part of this context. part of this context.

For example, For example, a web application located at /catalog in a a web application located at /catalog in a

web serverweb server the index.html file located at the base of the index.html file located at the base of

the web application hierarchy can be the web application hierarchy can be served to satisfy a request to served to satisfy a request to /catalog/index.html./catalog/index.html.

Page 25: Build a Web Application on J2EE

2525

WEB-INFWEB-INF

contains all things related to the contains all things related to the application that aren’t in the application that aren’t in the document root of the applicationdocument root of the application

WEB-INF node is not part of the WEB-INF node is not part of the public document tree of the public document tree of the application. No file contained in the application. No file contained in the WEB-INF directory may be served WEB-INF directory may be served directly to a client.directly to a client.

Page 26: Build a Web Application on J2EE

2626

Contents of the WEB-INF Contents of the WEB-INF directorydirectory

/WEB-INF/web.xml deployment /WEB-INF/web.xml deployment descriptordescriptor

/WEB-INF/classes/* directory for /WEB-INF/classes/* directory for servlet and utility classes. servlet and utility classes.

/WEB-INF/lib/*.jar area for Java /WEB-INF/lib/*.jar area for Java Archive files which contain servlets, Archive files which contain servlets, beans, and other utility classes beans, and other utility classes useful to the web application. useful to the web application.

Page 27: Build a Web Application on J2EE

2727

Customize Web Application Customize Web Application directorydirectory

W eb A p p / (W eb A p p lication R oot F old er)

Inde x.H T M LInde x.J S P

W E B _ IN F /

W E B .X M L

C la s s e s /

L ib /

S R C /

im ag es /

Page 28: Build a Web Application on J2EE

2828

Web.xmlWeb.xml

The web.xml file format is defined in The web.xml file format is defined in the Servlet Specification, so this file the Servlet Specification, so this file format will be used in every servlet-format will be used in every servlet-conforming Java servlet container. conforming Java servlet container.

This file format is used in two places in This file format is used in two places in Tomcat: $CATALINA_BASE/conf Tomcat: $CATALINA_BASE/conf directory directory

each web application.each web application.

Page 29: Build a Web Application on J2EE

2929

Deployment description of Web Deployment description of Web ApplicationApplication

Web.xmlWeb.xml

The deployment elements that The deployment elements that contain this information are:contain this information are:

env-entryenv-entry

ejb-refejb-ref

resource-refresource-ref

Page 30: Build a Web Application on J2EE

3030

Example of Web.xmlExample of Web.xml

<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>    <!DOCTYPE web-app<!DOCTYPE web-app (View Source for full doctype...) (View Source for full doctype...)> > - <web-app>- <web-app>    <description><description>Oracle Test AppOracle Test App</description> </description> - <listener>- <listener>    <listener-class><listener-class>StudentPackage.contextlisenterStudentPackage.contextlisenter</listener-class> </listener-class>    </listener></listener>

- <resource-ref>- <resource-ref>    <description><description>Oracle Datasource exampleOracle Datasource example</description> </description>    <res-ref-name><res-ref-name>jdbc/myoraclejdbc/myoracle</res-ref-name> </res-ref-name>    <res-type><res-type>javax.sql.DataSourcejavax.sql.DataSource</res-type> </res-type>    <res-auth><res-auth>ContainerContainer</res-auth> </res-auth>    </resource-ref></resource-ref>    </web-app></web-app>

Page 31: Build a Web Application on J2EE

3131

Configure resources used by Configure resources used by Web ApplicationWeb Application

use Server.xml to configure resourcesuse Server.xml to configure resources Web container runs in an object-oriented Web container runs in an object-oriented

wayway dynamically builds its object structure at dynamically builds its object structure at

runtime, based on the configuration filesruntime, based on the configuration files each major element in the each major element in the server.xmlserver.xml file file

creates a software "object," and the creates a software "object," and the ordering and nesting of these elements ordering and nesting of these elements sets up processing pipelines that allow you sets up processing pipelines that allow you to perform filtering, grouping.to perform filtering, grouping.

Page 32: Build a Web Application on J2EE

3232

Context in server.xmlContext in server.xml

A Context represents one web A Context represents one web application within a Tomcat instance.application within a Tomcat instance.

the web site is made up of one or the web site is made up of one or more Contexts. more Contexts.

Page 33: Build a Web Application on J2EE

3333

key attributes in a Context key attributes in a Context AttributeAttribute MeaningMeaning

crossContexcrossContextt

Specifies whether Specifies whether ServletContext.getContext(otherWebApp) ServletContext.getContext(otherWebApp) should succeed (true) or return null (false) should succeed (true) or return null (false)

debug debug Debugging level Debugging level

docBasedocBase URL relative to virtual hostURL relative to virtual host

pathpath Absolute path to the directory Absolute path to the directory

privilegedprivileged Specifies whether this context can run Specifies whether this context can run Container servlets, such as the Manager Container servlets, such as the Manager application application

reloadablereloadable Specifies whether servlet files on disk will Specifies whether servlet files on disk will be monitored, and reloaded if their be monitored, and reloaded if their timestamp changes timestamp changes

Page 34: Build a Web Application on J2EE

3434

Example of Server.xmlExample of Server.xml

<!-- buzzinservlet --> <Context <!-- buzzinservlet --> <Context path="/buzzin" path="/buzzin" docBase="/home/ian/javasrc/threadsdocBase="/home/ian/javasrc/threads/buzzin" debug="0" /buzzin" debug="0" reloadable="true"> </Context> reloadable="true"> </Context>