Create java ee web application in eclipse

This tutorial shows how to build some of the components needed for a Web Application. It demonstrates how to create Java Beans, JSF pages and provides a tour of major components in Oracle Enterprise Pack for Eclipse, and shows you how they are used to build a basic application.

Time to Complete

Approximately 30 minutes.

Topics

This tutorial covers the following topics:

Viewing Screenshots

Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.

Overview

In the tutorial, you learn how to create a Dynamic Web Project in the Oracle Enterprise Pack for Eclipse tool, define and start the WebLogic Server and additionally you create JSP pages. You see how to create bundle messages for internationalization and how to create page flow diagrams. You see how to add CSS.

Prerequisites

Before you begin this tutorial, you should:

Have access to or have installed Eclipse . You can download it from Oracle Technology Network. Unzip to a directory of your choice, which in this tutorial is referred to as ECLIPSE_HOME .

Have access to or have installed Oracle WebLogic Server 10.3. You can download it from Oracle Technology Network.

To install WebLogic, double click the .exe file to launch the Oracle Installer and install it into the directory of your choice, which in this tutorial is referred to as WEBLOGIC_HOME .

Since we are using WLS 10.3 and because Weblogic Server 10.3 requires JDK 1.6, OEPE 11g must be launched with JDK 1.6 as well. There are two ways to do this:

To implement the second option, locate the directory where the WebLogic JDK was installed. (for example: \jdk160_05\bin ) and copy the path in the clipboard.

Locate the ECLIPSE_HOME directory and open the eclipse.ini file using notepad.

Enter the following statements : -vm then copy the content of the clipboard.

Save and close the eclipse.ini file.

Launching Eclipse

Now that the environment is set, you can start Eclipse. To launch the tool, perform the following steps:

Start Eclipse by double clicking the Eclipse executable eclipse.exe found in the ECLIPSE_HOME directory.

Eclipse starts loading up and a Workspace Launcher dialog pops up. Specify a Workspace folder for your work.

Click OK.

The Eclipse Welcome screen appears.

Hover your mouse on each icon of the Welcome screen and review the possible options.

To start working, click the Workbench icon.

The term Workbench refers to the desktop development environment. The Workbench aims to achieve seamless tool integration and controlled openness by providing a common paradigm for the creation, management, and navigation of workspace resources.

The Eclipse IDE opens up.

Creating a Dynamic Web Project

The Project Explorer navigator allows you to create various type of projects. Depending on the nature of the project you create, a corresponding perspective will be used. A perspective defines the initial set and layout of views in the Workbench window. Within the window, each perspective shares the same set of editors. Each perspective provides a set of functionality aimed at accomplishing a specific type of task or works with specific types of resources. For example, the Java perspective combines views that you would commonly use while editing Java source files, while the Debug perspective contains the views that you would use while debugging Java programs.

To define a dynamic web project, perform the following steps:

A dynamic web project ties together various modules. To create a new web project, perform the following steps: Right click within the Project Explorer pane and select New --> Dynamic Web Project from context.

In the New Dynamic Web Project dialog, enter JSF_Intro as the project name, check the Use Default check box, and click the New button next to the Target Runtime field.

In the New Server Runtime Environment, select Oracle --> Oracle WebLogic Server 11gR1 PatchSet 1 and the Create a new local server check box.

Click Next.

In the following step of the wizard, click the Browse button next to the WebLogic Home field:

Specify the home path of WebLogic Server.

Click OK, then Next.

In the following step, check Local as the Server Type and click the Click here to launch Configuration Wizard to create a new domain link.

In the Fusion Middleware Configuration Wizard, select the Create a new WebLogic domain option.

Click Next.

In the following step, click Next to accept default values.

In the following step, click the Browse button next to the Domain location field.

In the Select a WebLogic Domain Directory, specify a directory name (Domain for example) and a location. Click OK and confirm the new directory creation.

If prompted to create the new directory, click OK to accept.

Back in the location and domain step, click Next.

In the Configure Administrator User Name and Password step, specify values. (weblogic/weblogic1 for example).

Click Next.

In the Configure Server Start Mode and JDK, choose the Development Mode and click Next.

Click Next.

In the Select Optional Configuration step, select the Administration Server option.

Click Next.

Click Next again to accept the default Administration Server Configuration values.

In the Configuration Summary step, click Create to proceed. Wait for the domain creation to be finished, then click the Done button.

Back in the New Server Runtime Environment dialog, click the Browse button next to the Domain Directory field to point to the base_domain directory you just created.

Click OK.

in the Define a WebLogic Server step, click the Finish button.

Back in the Dynamic Web Project, click the Modify button next to the Configuration field.

The Project Facets dialog shows the facets that are enabled for your current project, allowing you to set up your own facet configuration. In the Project Facets dialog, check the JavaServer Faces and JSTL Project Facet options to add these to the current configuration.

Click OK.

Back in the Dynamic Web Project, Click Next.

In the Java step, click Next.

In the Web Module step, click Next.

In the JSF Capabilities step, click Next.

Finally in the JSTL Library step, click Finish.

In the Open Associated Perspective dialog, click Yes to open the the proposed perspective (Java EE).

The Eclipse IDE should now look like the following:

Notice the project name in the left pane and the used perspective (Java EE) for this project in the top right corner.

Expand the JSF_Intro project node and review all the default components created for this new project.

J2EE architecture supports component-based development of multi-tier enterprise applications. A J2EE application system typically includes the following tiers:

Launching Oracle WebLogic Server

To launch WebLogic Server and run the default Index page, perform the following steps:

In the log window, open the Servers tab (Window --> Show View --> Servers) and click the Start icon to start Oracle WebLogic Server.

The Console pane opens up where you can follow the start operation. (To open the Console if not opened, select Window --> Show View --> Console)

The index.jsp node is the starting point for your application. In the Project Explorer, right click the index.jsp node and select Run As --> Run on Server.

In the Run on Server, click Finish to use the existing started server.

Click the Servers tab to see the new status:

The index.jsp displays in the embedded eclipse web browser.

Creating a Managed Bean

We're going to create a managed bean to handle login values such as name and email address. To do so, perform the following steps:

In the Project Explorer, expand the Faces Configuration node, right click the Managed Beans entry and select New Managed Bean from context.

In the New Managed Bean Wizard, check the Create a new Java class option.

Click Next.

In the following step, type demo as the package name and UserBean as the Name for the class. Leave other default values.

Click Next. Then click Next again.

In the Wizard Summary, click Finish.

The new bean appears as a Managed Bean and as a Java class in the Java Resources | src | demo nodes.

Double click the UserBean.java to open it in the Java editor.

Add 3 variable declaration statements to the class:

private String firstName;
private String lastName;
private String emailid;

Right click within the editor and select Quick Outline from context.

The quick outline displays exposing the variables defined so far in the Java class.

Press [Esc] to close the outline window. Notice that the outline is also visible in a specific Outline pane.

Right click within the editor inside the class delimiters (<>) and select Source --> Generate Getters and Setters from context.

In the Generate Getters and Setters dialog, click the Select All button. Notice that the Insertion point field lets you specify where you want the getters and setters statements to be added. Select After 'emailid'.

Click OK.

The new statements are added to the class.