J2ee Tutorial

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View J2ee Tutorial as PDF for free.

More details

  • Words: 1,427
  • Pages: 21
J2EE-Tutorial Developing a J2EE-Application with JBoss

Übung SAVES, Sommersemester 2006 Holger Klus Sebastian Herold Technische Universität Kaiserslautern Fachbereich Informatik AG Softwarearchitektur

Overview ƒ Application Scenario „Drink Account Manager“ ƒ Current situation ƒ Goals of „Drink Account Manager“

ƒ J2EE-Introduction ƒ ƒ ƒ ƒ ƒ ƒ ƒ

Short Overview Container-Concept Entity Beans Session Beans Servlets/JSP‘s Packaging and Deployment XDoclet

Application Scenario „Drink Account Manager“ ƒ

ƒ

Current situation

ƒ A printed list with available drinks and possible consumers is provided in our kitchen ƒ Every person makes a bar in the corresponding field if he removes a drink ƒ Additionally a price list is available ƒ Every 4-5 weeks a bill is sent to the consumers by E-Mail

Goals of „Drink Account Manager“

ƒ Making bars via Touch-Screen in the kitchen ƒ Automatic generation of bills and the corresponding E-Mail ƒ But first: Implementing basic functionality like - Show/Add/Edit/Delete -

Consumers Drinks Removals Prices Bills

Wasser (0,7 Liter)

Cola (0,5 Liter)

Apfelschorle (0,7 Liter)

Sebastian Herold Holger Klus



Getränk

Preis

Wasser (0,7 Liter)

0,40 €

Cola (0,5 Liter)

0,75 €

Apfelschorle (0,7 Liter)

0,70 €





Application Scenario „Drink Account Manager“ ƒ Implementation of this scenario using two different approaches ƒ Fat-Client-Approach - Client is a Java application using Hibernate for Object-Relational mapping - All data will be stored in a MySQL-Database

ƒ Ultra-Thin-Client-Approach (using J2EE) - Client accesses the application through a web interface - Web-pages are generated on server-side and will then be sent to the client - The application runs in an application server including - Business logic and - Persistence functionality - Also: dynamic generation of required web-pages

- Data will also be stored in a MySQL-Database

Relational DB-Schema tblBill pk_id fk_consumer dateOfIssue expirationDate balanced

tblConsumer pk_id firstName lastName

email

tblRemoval pk_id fk_consumer fk_bill fk_drink amount dateOfRemoval

tblDrink

tblPrice

pk_id name capacity

pk_id fk_drink amount validFrom validUntil

J2EE - Short Overview ƒ J2EE ≡ “Java 2 Platform Enterprise Edition” ƒ The newest version is called “Java Platform, Enterprise Edition (Java EE)”

ƒ Provides a programming platform for developing and running ƒ distributed, and ƒ multi-tier architecture ƒ Java applications

ƒ J2EE is based on software components executable in an application server ƒ There are specific runtime environments for specific components - Containers

ƒ Allows developers to create an enterprise application that is portable between platforms ƒ „Write once, run anywhere, and reuse everywhere“ ƒ Possible, because J2EE is standardized

J2EE – Short Overview ƒ One of the most important concepts in J2EE are Containers

ƒ Provide an environment in which the components can be executed in a controlled and managed way ƒ They provide services that the components can use either in a programmatic or a declarative way ƒ Allows declarative transaction management (only possible in the EJB-container)

ƒ Different types of Containers ƒ Application Container ƒ Applet Container ƒ EJB-Container

- Entity Beans, Session Beans, Message-driven Beans

ƒ Web-Container

- Servlets, JSPs

J2EE – Container-Concept

J2EE – Enterprise Java Beans (EJB) ƒ Three types of EJBs (all executed in the EJB-Container) ƒ Entity Beans - Provide an object-oriented view to the underlying persistent data - Container- vs. Bean Managed Persistence - Synchronous access using RMI-IIOP

ƒ Session Beans -

Modelling business processes Stateless vs. Stateful Session Beans They are conversational and perform specific actions Synchronous access using RMI-IIOP

ƒ Message-driven Beans - Similar to Session Beans but provide asynchronous access using JMS

J2EE – Bean-Usage ƒ Beans are registered in a JNDI-repository ƒ Lookup by name

ƒ Access Beans through interfaces ƒ Remote Interface - Interface to the application-specific services of the bean - setName() - getName() - getDrinkList()

ƒ Home Interface - Interface for managing bean instances - create() - findAll() - findByPrimaryKey()

ƒ Each type available in local and remote version (since EJB 2.0)

J2EE – Entity Beans ƒ An Entity Bean is a Java class with some additional features/attributes ƒ They can be made persistent in an relational database - Bean-Managed persistence (BMP)

- The programmer has to implement several callback methods like ejbCreate, ejbRemove, …

- Container-Managed persistence (CMP)

- Only a mapping to the relational DB has to be provided by the programmer, the rest will be managed by the container - Three descriptors involved - mysql-ds.xml (located in jboss-4.0.4RC1\server\default\deploy) - jbosscmp-jdbc.xml - ejb-jar.xml - Mapping of relations between beans is also done in these descriptors

ƒ Naming convention - setProperty() - getProperty()

EJB-QL (EJB Query Language) ƒ Defines queries for the finder and select methods of an entity bean with container-managed persistence ƒ The scope of an EJB-QL query spans the abstract schemas of related entity beans that are packaged in the same EJB jar-file. ƒ They are defined in the deployment descriptor of the entity bean (ejb-jar.xml). ƒ SELECT OBJECT(a) FROM Drink AS a ƒ SELECT DISTINCT OBJECT(p) FROM Drink d WHERE d.name = ?1 AND d.capacity = ?2

J2EE – Session Beans ƒ Used for realizing superior business logic ƒ Often their methods correspond to use cases and use services of one or many Entity Beans ƒ E.g. Methods which provides appropriate data for the presentation layer

ƒ Session Beans encapsulate Entity Beans ƒ Session Beans represent a classical facade Entity Bean Client

Session Bean

Entity Bean Entity Bean

Entity Bean

EJB-Container

J2EE – Value Objects / Data Access Objects (DAO) ƒ Value objects/DAOs are simple POJOs (plain old java objects) ƒ Are used to exchange application-specific data ƒ Example: DrinkListEntry ƒ Simple POJOs can be generated automatically

ƒ Important: ƒ Value Objects have to be serializable

J2EE - Servlets ƒ ƒ ƒ ƒ

Special Java classes located on the server Appropriate for the implementation of web-based user interfaces Dynamic generation of web content instead of returning static content The client invokes a servlet using an HTTP request

ƒ

Servlets can access components running in the EJB container (-> Session Beans) But: html-code is generated using println-statements

ƒ

ƒ The web container forwards the request to the servlet. ƒ The servlet processes it and generates the content dynamically. ƒ The web container then transmits the response back to the web server and finally to the client.

ƒ PrintWriter out = resp.getWriter(); ƒ out.println(""); ƒ …<br /> <br /> ƒ<br /> <br /> Disadvantages<br /> <br /> ƒ Html mixed with Java ƒ Recompilation required after changes in the source code<br /> <br /> J2EE - JSPs ƒ ƒ<br /> <br /> Special html-pages located on the server They can be developed like html-pages but can also include Java-code ƒ Naturally appropriate for the implementation of web-based user interfaces ƒ Not particular well suited to perform processing logic<br /> <br /> ƒ<br /> <br /> JSPs are transformed into Servlets at runtime ƒ No Recompilation required after changes of the layout<br /> <br /> ƒ<br /> <br /> Some important jsp-Tags ƒ <% … %> - Here you can insert Java code, so called “Scriptlets”<br /> <br /> ƒ <%@ … %> - Among others you can insert an import-statement with libraries to be included - Content of this tag is called “Directive”<br /> <br /> ƒ <jsp:forward> - Can be used to redirect the request to another jsp-page<br /> <br /> ƒ<br /> <br /> Important ƒ jsp-tags, names, parameters, … are case-sensitive<br /> <br /> J2EE – Packaging and Deployment ƒ Packaging ƒ All components and deployment descriptors have to be packaged in a specific way ƒ .ear - .war - *.jsp - WEB-INF - jboss-web.xml - web.xml<br /> <br /> - .jar - META-INF - ejb-jar.xml - jboss.xml - jbosscmp-jdbc.xml<br /> <br /> - META-INF - application.xml<br /> <br /> J2EE – Deployment and Packaging ƒ Deployment ƒ Step of transferring the J2EE-Application to the application server ƒ Only the .ear-file has to be deployed<br /> <br /> ƒ Doing all that stuff manually would take a lot of time! ƒ Therefore XDoclet has been developed in order to automate these tasks like - Generating required interfaces - Generating deployment descriptors - …<br /> <br /> XDoclet ƒ Open Source code generation engine ƒ Enables Attribute-Oriented Programming for Java ƒ Adding meta data to the java source<br /> <br /> ƒ XDoclet parses the source files and generates artifacts such as XML descriptors and/or source code from it ƒ Currently XDoclet can only be used as part of the build process utilizing Jakarta Ant ƒ Details look at ƒ http://xdoclet.sourceforge.net/xdoclet/index.html<br /> <br /> XDoclet – Main Idea XDoclet-Tags<br /> <br /> Java-Files<br /> <br /> XDoclet-build.xml<br /> <br /> ant<br /> <br /> .java<br /> <br /> web.xml<br /> <br /> jboss.xml<br /> <br /> ejb-jar.xml<br /> <br /> …<br /> <br /> Advantages/Disadvantages of J2EE ƒ Advantages<br /> <br /> ƒ J2EE provides a complete architecture for developing<br /> <br /> - Distributed systems including object persistence, session tracking, transaction management, …<br /> <br /> ƒ Separation of technical and application-specific code - Deployment descriptors - Container Managed Persistence<br /> <br /> ƒ Disadvantages<br /> <br /> ƒ Very complex technology<br /> <br /> - Even simple examples require many interfaces, bean classes, deployment descriptors, …<br /> <br /> ƒ Many errors occur only at runtime (several steps required until the application is running) -<br /> <br /> Compilation Packaging Deployment Running the application </div> </div> <hr /> <h4>Related Documents</h4> <div class="row"> <div class="col-lg-2 col-md-4 col-sm-6 col-6"> <div class="card item-doc mb-4"> <a href="https://pdfcoke.com/documents/j2ee-tutorial-w63yvjnw93mx" class="d-block"><img class="card-img-top" src="https://pdfcoke.com/img/crop/300x300/w63yvjnw93mx.jpg" alt=""/></a> <div class="card-body text-left"> <h5 class="card-title"><a href="https://pdfcoke.com/documents/j2ee-tutorial-w63yvjnw93mx" class="text-dark">J2ee Tutorial</a></h5> <small class="text-muted float-left"><i class="fas fa-clock"></i> October 2019</small> <small class="text-muted float-right"><i class="fas fa-eye"></i> 18</small> <div class="clearfix"></div> </div> </div> </div> <div class="col-lg-2 col-md-4 col-sm-6 col-6"> <div class="card item-doc mb-4"> <a href="https://pdfcoke.com/documents/j2ee-263exqx71z04" class="d-block"><img class="card-img-top" src="https://pdfcoke.com/img/crop/300x300/263exqx71z04.jpg" alt=""/></a> <div class="card-body text-left"> <h5 class="card-title"><a href="https://pdfcoke.com/documents/j2ee-263exqx71z04" class="text-dark">J2ee</a></h5> <small class="text-muted float-left"><i class="fas fa-clock"></i> November 2019</small> <small class="text-muted float-right"><i class="fas fa-eye"></i> 24</small> <div class="clearfix"></div> </div> </div> </div> <div class="col-lg-2 col-md-4 col-sm-6 col-6"> <div class="card item-doc mb-4"> <a href="https://pdfcoke.com/documents/j2ee-6v3rwm95pmoe" class="d-block"><img class="card-img-top" src="https://pdfcoke.com/img/crop/300x300/6v3rwm95pmoe.jpg" alt=""/></a> <div class="card-body text-left"> <h5 class="card-title"><a href="https://pdfcoke.com/documents/j2ee-6v3rwm95pmoe" class="text-dark">J2ee</a></h5> <small class="text-muted float-left"><i class="fas fa-clock"></i> December 2019</small> <small class="text-muted float-right"><i class="fas fa-eye"></i> 25</small> <div class="clearfix"></div> </div> </div> </div> <div class="col-lg-2 col-md-4 col-sm-6 col-6"> <div class="card item-doc mb-4"> <a href="https://pdfcoke.com/documents/j2ee-1d3qp2n67og9" class="d-block"><img class="card-img-top" src="https://pdfcoke.com/img/crop/300x300/1d3qp2n67og9.jpg" alt=""/></a> <div class="card-body text-left"> <h5 class="card-title"><a href="https://pdfcoke.com/documents/j2ee-1d3qp2n67og9" class="text-dark">J2ee</a></h5> <small class="text-muted float-left"><i class="fas fa-clock"></i> November 2019</small> <small class="text-muted float-right"><i class="fas fa-eye"></i> 24</small> <div class="clearfix"></div> </div> </div> </div> <div class="col-lg-2 col-md-4 col-sm-6 col-6"> <div class="card item-doc mb-4"> <a href="https://pdfcoke.com/documents/j2ee-xlo6evvlvz61" class="d-block"><img class="card-img-top" src="https://pdfcoke.com/img/crop/300x300/xlo6evvlvz61.jpg" alt=""/></a> <div class="card-body text-left"> <h5 class="card-title"><a href="https://pdfcoke.com/documents/j2ee-xlo6evvlvz61" class="text-dark">J2ee</a></h5> <small class="text-muted float-left"><i class="fas fa-clock"></i> November 2019</small> <small class="text-muted float-right"><i class="fas fa-eye"></i> 22</small> <div class="clearfix"></div> </div> </div> </div> <div class="col-lg-2 col-md-4 col-sm-6 col-6"> <div class="card item-doc mb-4"> <a href="https://pdfcoke.com/documents/j2ee-clustering-8m3kvrd0q4on" class="d-block"><img class="card-img-top" src="https://pdfcoke.com/img/crop/300x300/8m3kvrd0q4on.jpg" alt=""/></a> <div class="card-body text-left"> <h5 class="card-title"><a href="https://pdfcoke.com/documents/j2ee-clustering-8m3kvrd0q4on" class="text-dark">J2ee Clustering</a></h5> <small class="text-muted float-left"><i class="fas fa-clock"></i> May 2020</small> <small class="text-muted float-right"><i class="fas fa-eye"></i> 3</small> <div class="clearfix"></div> </div> </div> </div> </div> </div> </div> </div> </div> <footer class="footer pt-5 pb-0 pb-md-5 bg-primary text-white"> <div class="container"> <div class="row"> <div class="col-md-3 mb-3 mb-sm-0"> <h5 class="text-white font-weight-bold mb-4">Our Company</h5> <ul class="list-unstyled"> <li><i class="fas fa-location-arrow"></i> 3486 Boone Street, Corpus Christi, TX 78476</li> <li><i class="fas fa-phone"></i> +1361-285-4971</li> <li><i class="fas fa-envelope"></i> <a href="mailto:info@pdfcoke.com" class="text-white">info@pdfcoke.com</a></li> </ul> </div> <div class="col-md-3 mb-3 mb-sm-0"> <h5 class="text-white font-weight-bold mb-4">Quick Links</h5> <ul class="list-unstyled"> <li><a href="https://pdfcoke.com/about" class="text-white">About</a></li> <li><a href="https://pdfcoke.com/contact" class="text-white">Contact</a></li> <li><a href="https://pdfcoke.com/help" class="text-white">Help / FAQ</a></li> <li><a href="https://pdfcoke.com/account" class="text-white">Account</a></li> </ul> </div> <div class="col-md-3 mb-3 mb-sm-0"> <h5 class="text-white font-weight-bold mb-4">Legal</h5> <ul class="list-unstyled"> <li><a href="https://pdfcoke.com/tos" class="text-white">Terms of Service</a></li> <li><a href="https://pdfcoke.com/privacy-policy" class="text-white">Privacy Policy</a></li> <li><a href="https://pdfcoke.com/cookie-policy" class="text-white">Cookie Policy</a></li> <li><a href="https://pdfcoke.com/disclaimer" class="text-white">Disclaimer</a></li> </ul> </div> <div class="col-md-3 mb-3 mb-sm-0"> <h5 class="text-white font-weight-bold mb-4">Follow Us</h5> <ul class="list-unstyled list-inline list-social"> <li class="list-inline-item"><a href="#" class="text-white" target="_blank"><i class="fab fa-facebook-f"></i></a></li> <li class="list-inline-item"><a href="#" class="text-white" target="_blank"><i class="fab fa-twitter"></i></a></li> <li class="list-inline-item"><a href="#" class="text-white" target="_blank"><i class="fab fa-linkedin"></i></a></li> <li class="list-inline-item"><a href="#" class="text-white" target="_blank"><i class="fab fa-instagram"></i></a></li> </ul> <h5 class="text-white font-weight-bold mb-4">Mobile Apps</h5> <ul class="list-unstyled "> <li><a href="#" class="bb-alert" data-msg="IOS app is not available yet! Please try again later!"><img src="https://pdfcoke.com/static/images/app-store-badge.svg" height="45" /></a></li> <li><a href="#" class="bb-alert" data-msg="ANDROID app is not available yet! Please try again later!"><img style="margin-left: -10px;" src="https://pdfcoke.com/static/images/google-play-badge.png" height="60" /></a></li> </ul> </div> </div> </div> </footer> <div class="footer-copyright border-top pt-4 pb-2 bg-primary text-white"> <div class="container"> <p>Copyright © 2024 PDFCOKE.</p> </div> </div> <script src="https://pdfcoke.com/static/javascripts/jquery.min.js"></script> <script src="https://pdfcoke.com/static/javascripts/popper.min.js"></script> <script src="https://pdfcoke.com/static/javascripts/bootstrap.min.js"></script> <script src="https://pdfcoke.com/static/javascripts/bootbox.all.min.js"></script> <script src="https://pdfcoke.com/static/javascripts/filepond.js"></script> <script src="https://pdfcoke.com/static/javascripts/main.js?v=1732426654"></script> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-144986120-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-144986120-1'); </script> </body> </html>