Design Patterns Java EE 6

De $1

Version de 14:59, 30 Nov 2021

cette version.

Revenir à liste des archives.

Voir la version actuelle

Introduction

These lab exercices will show you the use of several design patterns with Java EE 6.

Software installation

You will use both Eclipse/Weblogic/MySQL and netbeans 7.2/glassfish/JavaDB for these exercises. Why two different environments ? Because developement with JSF 2 is a lot easier with netbeans and we do not have much time... So, some examples will be run using Eclipse, some other using netbeans...

Install Weblogic + Oracle enterprise pack for eclipse

Install the file named oepe-indigo-installer-12.1.1.0.1.201203120349-12.1.1-win32.exe get all the default options. We assume that there is a JDK installed on your system.

Once the installation is finished, look at your windows start menu and run "Oracle Enterprise Pack For Eclipse/Weblogic server 12c/Tools/configuration wizard" and create a default domain, using the default options. The instructor will show on the video projector what to set.

When prompted for an admin password, try to enter one you will remember !!!!

Normally, if everything went fine, you should see a new menu in your start menu: "Oracle Enterprise Pack for Eclipse/user projects/base domain"... from this menu you can start the admin server, then when the admin server has been started (in a dos window you should see the message "server started in RUNNING mode"...), you can use the menu to open the admin console. 

If there is an error there, something went wrong, call your instructor...

Install MySQL

There are many version of MySQL installers available. We provide a zip that do not need any install at all. Just unzip the file mysql-noinstall-5.1.35-win32.zip in c:\mysql for example.

In order to run the MySQL server, open a DOS window, go to c:\mysql\bin\ and run "mysqld.exe", this will start the MySQL daemon. Open another DOS window, go to the same directory and run "mysql.exe -u root", the admin tool. 

Enter "show databases;" to see all the databases available. This should display a table with some prefefined databases.

Install Netbeans

In order to install netbeans 7.2, just run netbeans-7.2.1-ml-javaee-windows.exe" and use all the default options.

The Bookstore example : shows JSP / Servlet model 2 approach (MVC)

This tutorial is available on the web at : http://wiki4.caucho.com/Java_EE_Tuto...d_Servlets_3.0 but we will just use it with WebLogic instead of with the Resin server.

Step 01 : a model, a facade/DAO, a controller Servlet, a JSP for a table view

You follow the tutorial for the first step : http://wiki4.caucho.com/Building_a_s...listing_in_JSP but when in the tutorial they ask to select Resin as a new runtime environment, just select Weblogic in the list. The rest of the tutorial is ok... Or you can just open the Eclipse project provided named "BookStoreStep01", that corresponds to this part of the tutorial.

If you follow the tutorial, you will get a project like this:

 Book1.jpg

With :

  • A Model Book.java in the com.bookstore package,
  • A facade / DAO with its interface BookRepository.java and its implementation in BookStoreImpl.java,
  • A Servlet that acts as HTTP controller in the file BookListServlet.java located in the com.bookstore.web package,
  • A JSP that acts as a view, in the WebContent/WEB-INF/pages/book-list.jsp page. Thus view references the model using the EL langage.

In order to run and deploy this project, use the Java EE perspective, go to the "server tab", right click on "oracle weblogic..." and chose "add and remove". Then select your project BookStoreStep01 and Ok. This will deploy your project on weblogic. Then use "run on server" on your project. This should display a list of books in the JSP page.

Look at how the code is organized, how we go from the Servlet to the JSP etc. This examples uses CDI for injecting the Facade into the Servlet using CDI, like explained in the course.

Step 02 : adding the CRUD operations...

This is the tutorial part 2: http://wiki4.caucho.com/Java_EE_Serv...kstore_listing

It is also available in the BookStoreStep02 Eclipse project.

In this step, a new Servlet has been added for handling update/insert new book operations, as well as a new JSP that will display a form that will be use for both editing an existing book or creating a new book. The business part is already implemented in the facade, we are just dealing with HTTP control and view here. The link with the table view is just a <a href> added in the table.

Step 03: just adding come CSS, headers and footers...

This step is not very relevant to our design pattern course, you may check it at : http://wiki4.caucho.com/Java_EE_Serv..._for_bookstore

it corresponds to the BookStoreStep03 Eclipse project.

Step 04: Add a second implementation for the facade, that uses JDBC, use injection with qualifiers

This example corresponds to this tutorial: http://wiki4.caucho.com/Java_EE_Serv...kstore_example