Build a Web Application on J2EE 1
34 Slides251.50 KB
Build a Web Application on J2EE 1
J2EE Scenario Client – Web Server – EIS Resources Client – Application Server – EIS Resources Client – Web Server – Application Server – EIS Resources 2
Client – Web Server – EIS Resources S e rv le t C lie n t HTM L HTTP X M L JS P JD B C D a ta B a s e e X M L 3
Business to Business JM S B ro w se r JS P JN D I S e rv le t S ta n d -a lo n e C lin e t L egacy S y s te m Jav a S erv er JD B C D a ta b a s e R M I JA V A ID L D is t r ib u t e CO RBA O b je c t 4
Web Application A web application is a collection of servlets, html pages, classes, and other resources that can be bundled and run on multiple containers from multiple vendors. A Web application is located on a central server and provides service to a variety of clients. Web applications provide dynamic and interactive content to browser-based clients. 5
Web Application Environment D a ta b a s e B ro w ser W eb C o n ta in e r A p p lic a tio n C o n ta in e r JD K E IS D is tr ib u te C O R B A O b je c ts O p e r a tio n S y s te m 6
JDK All J2EE applications require the Java Developers Kit to run Java classes or the Java Virtual Machine (JVM). Download JDK from java.sun.com for free Configure several environment variables. JAVA HOME CLASSPATH 7
Web Application Structure C o n n e cto r W eb C o n ta in e r B ro w ser A p p lic a t io n C o n ta in e r JSP S e r v le ts EJB J a v a C la s s e s D a ta b a s e JD BC JND I R M I . . E IS D istr ib u te C O R B A O b je cts 8
Container The container is an independent application that creates an environment for web components. 9
Functions of Container Life cycle management for components. Environment configuration. Resources. 10
Web Container An entity that implements the Web component contract of the J2EE architecture. specify a runtime environment for Web components that includes security, concurrency, life cycle management, transaction, deployment, and other services provide the same services as a JSP container and a federated view of the J2EE platform APIs. can run a Web application that is tagged as distributable and that executes across multiple Java virtual machines running on the same host or on different hosts. 11
Web Container Provider Open Source Tomcat Business Product WebLogic WebShpere 12
Tomcat Just a JSP, Servlets Container jakarta.apache.org/tomcat/ index.html 13
Application Container An entity that implements the Java Classes contract of the J2EE architecture. Java Classes include: EJB other Java Classes access to the J2EE service and communication APIs. 14
Application Container Provider Open Source JBOSS Business Product WebLogic WebShpere Silverstream 15
Connectors The connector is where the abstract really meets the concrete. A connector is a translator between an enterprise information system and the J2EE interfaces. Another type of connector, a JNDI Service Provider Interface, provides access to naming and directory services. 16
JDBC a JDBC driver, provides access to databases. 17
JNDI provides access to naming and directory services provides a link between Java code and various naming and directory services such as Domain Name System (DNS), Novell Directory Service (NDS), CORBA, and Network Information System (NIS). allows you to access code and resources across widely separated platforms and directory structures through the use of a simple naming scheme. 18
Tools Ant IDE Jbuilder NetBeans 19
Data format used in Web Application HTML JSP Image files Gif JPEG Class file Source code Complied code XML JAR file: used in J2EE for packaging EJBs and clientside Java Applications WAR file: web applications made from Servlets, JSPs, and supporting classes EAR file: contain all of the components that make up a particular J2EE application 20
Web Application can be exist in WAR files directory 21
Web Application Archive File Web applications can be packaged and signed, using the standard Java Archive tools, into a Web ARchive format (war) file. When packaged into such a form, a METAINF directory will be present which contains information useful to the Java Archive tools. 22
Basic Web Application Directory W e b A p p / (W e b A p p lic a tio n R o o t F o ld e r ) In d e x .H T M L In d e x .J S P W E B IN F / W E B .X M L C la s s e s / L ib / 23
Root The root of this hierarchy serves as a document root for serving files that are part of this context. For example, a web application located at /catalog in a web server the index.html file located at the base of the web application hierarchy can be served to satisfy a request to /catalog/index.html. 24
WEB-INF contains all things related to the application that aren’t in the document root of the application WEB-INF node is not part of the public document tree of the application. No file contained in the WEB-INF directory may be served directly to a client. 25
Contents of the WEB-INF directory /WEB-INF/web.xml deployment descriptor /WEB-INF/classes/* directory for servlet and utility classes. /WEB-INF/lib/*.jar area for Java Archive files which contain servlets, beans, and other utility classes useful to the web application. 26
Customize Web Application directory W e b A p p / (W e b A p p lic a tio n R o o t F o ld e r ) In d e x .H T M L In d e x .J S P SRC / im a g e s / W E B IN F / W E B .X M L C la s s e s / L ib / 27
Web.xml The web.xml file format is defined in the Servlet Specification, so this file format will be used in every servletconforming Java servlet container. This file format is used in two places in Tomcat: CATALINA BASE/conf directory each web application. 28
Deployment description of Web Application Web.xml The deployment elements that contain this information are: env-entry ejb-ref resource-ref 29
Example of Web.xml ?xml version "1.0" encoding "UTF-8" ? !DOCTYPE web-app (View Source for full doctype.) - web-app description Oracle Test App /description - listener listener-class StudentPackage.contextlisenter /listener-class /listener - resource-ref description Oracle Datasource example /description res-ref-name jdbc/myoracle /res-ref-name res-type javax.sql.DataSource /res-type res-auth Container /res-auth /resource-ref /web-app 30
Configure resources used by Web Application use Server.xml to configure resources Web container runs in an object-oriented way dynamically builds its object structure at runtime, based on the configuration files each major element in the server.xml file creates a software "object," and the ordering and nesting of these elements sets up processing pipelines that allow you to perform filtering, grouping. 31
Context in server.xml A Context represents one web application within a Tomcat instance. the web site is made up of one or more Contexts. 32
key attributes in a Context Attribute Meaning crossContex Specifies whether ServletContext.getContext(otherWebApp) t should succeed (true) or return null (false) debug docBase path privileged Debugging level reloadable Specifies whether servlet files on disk will be monitored, and reloaded if their URL relative to virtual host Absolute path to the directory Specifies whether this context can run Container servlets, such as the Manager application 33
Example of Server.xml !-- buzzinservlet -- Context path "/buzzin" docBase "/home/ian/javasrc/threads /buzzin" debug "0" reloadable "true" /Context 34