JavaEE6 Weblogic exercice 1

De $1

Version de 06:11, 20 Avr 2024

cette version.

Revenir à liste des archives.

Voir la version actuelle

Introduction

In this exercice we will write a JavaEE application that uses the new "web profile": a single project that can use JSF/JSP/Servlets/Web Services/EJBs/JPA with some limitations (no message driven beans, no timer, etc.) and one advantage: it is easier to manage as all components are located in a single project, and deployment is done in a single jar file. We will use a javaDB/Derby database for this application.

Install the different components

  1. You will need to install weblogic 12c with the Oracle Enterprise Pack for Eclipse (an Eclipse 3.7 for java EE developers that is pre configured with the Weblogic server plugin and some other goodies). Follow the directives of your instructor. Do not forget to create a default domain in your server. When asked for a password, please enter one you will not forget !
  2. Install the JavaDB/Derby database. Follow the instructions from this page (installing a java DB database): Weblogic / Java EE6 FAQ and Guides.
  3. In some other exercices we will use a MySQL database. You may want to install it now also. Again, look at the proper section in:  Weblogic / Java EE6 FAQ and Guides.

Creating a "web profile JavaEE 6 project", write a servlet and an EJB for testing

Create a standard dynamic web project using Eclipse, call it for example "Exo1WebProfile". Click twice on the next button and in the last screen, check "Generate web.xml descriptor". Normally we do not need any XML settings in that file (JavaEE 6 replaced the need to XML settings by code annotations) but it will be useful to set the starting URL when we run the project in that file.

Add a Servlet in the project, call it TestServlet, and add it in a package named "servlets". Click finish. Add some lines in the doGet() method, like these:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the response message's MIME type.
response.setContentType("text/html;charset=UTF-8");
// Allocate a output writer to write the response message into the network socket.
PrintWriter out = response.getWriter();

out.println("<h1>Welcome to Exo1 test servlet!</h1>");
}