Home > Articles

Deploying Your First Web Application Using the WebLogic Builder

This section showcases ways you can create, package, assemble, and deploy a simple Web application using the WebLogic Builder. Because this may be your first J2EE Web application, details of each step are discussed briefly. However, there is a detailed discussion of deploying Web and Enterprise applications to the WebLogic Server in Chapter 6, "Packaging, Assembling, and Deploying J2EE Applications."

A typical Web application is composed of the following elements:

  • One or more J2EE Web components such as servlets and Java Server Pages (JSPs).

  • Application resources such as JSP tag libraries, HTML pages, and image files.

  • An application-specific XML-based deployment descriptor file named web.xml, which lists your application's J2EE components and their configurations as J2EE modules. Each J2EE module is a collection of one or more J2EE components of the same container type (Web or EJB) that are represented by one component deployment descriptor for that type in the web.xml file.

  • A WebLogic-specific deployment descriptor file named weblogic.xml, which defines how named resources in the web.xml file are mapped to WebLogic Server resources. Examples of weblogic.xml attributes include HTTP session parameters, HTTP cookie parameters, JSP parameters, resource references, security role assignments, and container attributes.

The HelloWorldApp example described in the following sections is composed of a Welcome HTML page and a servlet, which returns a Hello World HTML page to your Web browser upon invocation. You will use the WebLogic Builder to generate the application deployment descriptors (web.xml and weblogic.xml) and then assemble the application resources into an exploded directory format, which will then be deployed to the WebLogic Server.

Follow the steps described in these sections to create, package, assemble, and deploy your first Web application to the WebLogic Server.

Step 1: Creating the Web Application Directory Structure

All J2EE Web applications use a standard hierarchical directory structure to maintain their application resources (servlets, classes, static files, and other resources). This directory structure is described in Table 3.2.

Table 3.2 The Hierarchical Directory Structure of a Web Application

Directory

Description

root/

The root directory of your Web application is known as the document root. This is the location where you will place all your static content files, such as HTML and Java Server Pages, which you want to be accessible to your client (Web browser).

root/WEB-INF

The root of the WEB-INF directory is the location for the web.xml and weblogic.xml deployment descriptors. All files and directories under the WEB-INF directory are considered private and accessible only to the WebLogic Server.

(The WEB-INF directory name needs to be uppercase.)

root/WEB-INF/classes

The directory location for all server-side Java class files.

root/WEB-INF/lib

The directory location for JAR files.


The directory structure described in Table 3.2 complies with the J2EE specification and provides the foundation to assemble and deploy your Web application with any one of the following methods:

  • Creating a 1WAR archive file of the contents of the document root directory, including all subdirectories. This deployment format allows you to deploy the Web application from a remote machine directly to the Administration Server, which can then propagate the Web application as a WAR file to any of its Managed Servers.

  • Deploying the Web application as a collection of class files directly from the Web application directory. This type of deployment is known as the exploded directory format of deployment and requires the Web application directory to exist on the same machine as the target Administration Server. This is the method you will use to deploy your Web application.

WebLogic provides a default Web applications directory named applications, which you can find under your WebLogic Server domain directory. For the purposes of following this example, create a directory structure as specified in Table 3.2, using the name HelloWorldApp as your document root. Your HelloWorldApp application directory should resemble Figure 3.8.

Figure 3.8Figure 3.8 Your HelloWorldApp application directory.

Step 2: Creating Your Welcome Page

Typically, a Web application contains a Welcome page as an entry point to a Web application. Even though this example is relatively simple, you can create a Welcome page to call the servlet you will create shortly.

Use the following HTML to create your Welcome page and save the HTML file as index.html in the root of your HelloWorldApp directory:

<html>
<head>
<title>Welcome to my HelloWorldApp</title>
</head>
<body>
<p> This is the default welcome page for this example.
<p> <a href="./MyServlet">Click here</a> to call the Hello World servlet.
</body>
</html>

Step 3: Creating and Compiling Your Hello World Servlet

A complete discussion of servlets is outside the scope of this book. However, for the purposes of this example, follow these steps to create and compile a servlet named MyServlet, which is part of a package named objectmind.servlets:

  1. Open a text editor and enter the following Java code:

    package objectmind.servlets;
    
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    
    public class MyServlet extends HttpServlet {
     public void service(HttpServletRequest req,
          HttpServletResponse res)
      throws IOException
     {
     res.setContentType("text/html");
     PrintWriter out = res.getWriter();
     out.println("<html><head><title>" +
        "Hello World!</title></head>");
     out.println("<body><h1>Hello World!</h1></body></html>");
     }
    }
  2. Save the Java code as a file named MyServlet.java in the root of your HelloWorldApp directory.

  3. From the command line, change the directory to your HelloWorldApp directory and set up your Java environment by invoking the setEnv script.

  4. From the command line in your HelloWorldApp directory, compile the MyServlet.java file using the following javac syntax:

    javac -d WEB-INF/classes MyServlet.java
  5. This command creates the MyServlet.class file in a directory structure under the Web-INF/classes directory according to the package name.

Step 4: Starting the WebLogic Builder

Now that you have created your J2EE components and HTML files, it is time to start using the WebLogic Builder to assemble and deploy your Web application.

Start the WebLogic Builder by choosing Start, Programs, BEA WebLogic Platform 7.0, WebLogic Server 7.0, WebLogic Builder.

Alternatively, you can start the WebLogic Builder from the command line by using the following command:

startWLBuilder.cmd

After the WebLogic Builder is launched, choose File, Open. From the dialog box, you can select an exploded or archived J2EE module. For this example, you have so far partially created an exploded Web application. Hence, select the HelloWorldApp directory, as shown in Figure 3.9, and click Open.

Figure 3.9Figure 3.9 Select your Web application using the WebLogic Builder.

After you click Open, the WebLogic Builder tries to locate and read any deployment descriptors associated with the J2EE module that you have selected to open. Because you have not created any deployment descriptors yet, the WebLogic Builder prompts you to allow it to search for Web modules or classes in your application directory and create the deployment descriptors for you, as shown in Figure 3.10. Click Yes.

Figure 3.10Figure 3.10 The WebLogic Builder's no deployment descriptor prompt.

When you open the HelloWorldApp module in the WebLogic Builder, you see a screen similar to Figure 3.11.

Figure 3.11Figure 3.11 The WebLogic Builder screen.

The WebLogic Builder screen is divided into the following panes:

  • The left pane is a hierarchical tree representation of the J2EE module you have opened. You can use this pane to explore and select the components of your Web application.

  • The right pane consists of tabbed panels with fields and other controls for editing the deployment descriptor elements of the J2EE module.

  • The bottom pane is activated through the View menu. You can use this pane to see information and error messages generated by the WebLogic Builder during the opening, creation, or deployment of a J2EE module.

The WebLogic Builder does its best in ensuring the values assigned to the deployment descriptor elements in the web.xml and weblogic.xml files are correct. However, because they are auto-generated, often you will need to create, modify, or delete certain deployment descriptor elements.

You can edit the deployment descriptors using the WebLogic Builder, or you can directly edit the web.xml and weblogic.xml files using an XML editor, such as the BEA XML Editor. In this example, you will edit the deployment descriptor files using the WebLogic Builder.

Because you have just created your deployment descriptors, to physically save them to your WEB-INF directory, you need to save your J2EE module. After you complete this save operation, you will see the web.xml and weblogic.xml files in the root of your WEB-INF directory.

Step 5: Assembling the HelloWorldApp Web Application

Up to now, you have partially created the HelloWorldApp Web application. The next step is to assemble the components of the application (servlets and HTML pages) so they are reflected in the deployment descriptors as one Web application. Follow these steps to assemble your HelloWorldApp application:

  1. Because you have created a Welcome page named index.html, you need to specify it in the WebLogic Builder. Select the HelloWorldApp identifier in the left pane, and in the corresponding Welcome Files tab, remove the index.jsp and index.htm files so that the index.html file is explicitly stated as the Welcome page, as illustrated in Figure 3.12.

Figure 3.12Figure 3.12 Assign the Welcome page.

  1. So far, the MyServlet servlet has only been compiled and placed into an appropriate directory structure under the WEB-INF directory. When you allowed the WebLogic Builder to create the deployment descriptors, it should have automatically discovered your MyServlet servlet and added an entry to the Web.xml file as a J2EE component of your Web application.

    To ensure this procedure occurred and the appropriate entries were specified as default by the WebLogic Builder, select the Servlets folder in the left pane. If the MyServlet node exists, select it and ensure the following information is specified correctly, as illustrated in Figure 3.13.

    • Servlet Name= MyServlet

    • Server Class = objectmind.servlets.MyServlet

    • URL Mappings = /MyServlet/*

    If the MyServlet servlet has not been discovered by the WebLogic Builder, click Add in the corresponding right pane. This operation launches a window for you to add the preceding information.

    The URL Mapping allows you to call the servlet directly from a Web browser after the Web application is deployed, thus allowing you to test the operation of a servlet. After you validate or enter your MyServlet information, click OK.

Figure 3.13Figure 3.13   Configure the MyServlet servlet deployment descriptor information.

  1. Now save your deployment descriptors by choosing File, Save. Your simple HelloWorldApp application is now assembled and ready to be deployed.

Step 6: Deploying Your Web Application

You have two options for deploying your HelloWorldApp application. Either you can create a WAR archive file of the entire contents of the HelloWorldApp directory, or you can deploy your application directly from the HelloWorldApp directory as long as the target Administration Server is hosted locally. This exploded directory deployment is possible because the web.xml and weblogic.xml deployment descriptors have been created and edited to reflect the J2EE components and other files that constitute your Web application.

NOTE

If you have enabled WebLogic autodeployment using -Dweblogic.ProductionModeEnabled=false, your application will automatically be deployed. However, the .jar, .war, and .ear files of the exploded directory must be contained within the applications directory.

The difference between these two deployment methods in the WebLogic Builder is that in an exploded directory deployment, the name of the Web application is stated by the name of the document root directory, which in this case is HelloWorldApp. In the WAR archive deployment method, the name of the Web application is governed by the name you assign to the WAR archive file, and you can deploy the Web application to a remote Administration Server.

The following steps will guide you through the deployment procedures for your exploded directory Web application:

  1. Connect to the target WebLogic Administration Server by choosing Tools, Connect to Server. In the launched dialog box, enter your specific WebLogic connection information, as shown in Figure 3.14, and click Connect.

Figure 3.14Figure 3.14   Connect to the WebLogic Server.

  1. To deploy your Web application, select Tools, Deploy Module. From the launched Deploy screen, as shown in Figure 3.15, click Deploy to initiate deployment of your HelloWorldApp application to the WebLogic Server.

Figure 3.15Figure 3.15 Deploying HelloWorldApp using the WebLogic Builder.

To validate your application has been deployed, you can open the Deploy screen by choosing Tools, Deploy Module and clicking the Manage Deployments tab. Here, you can validate the status of your Web application on the WebLogic Server. If it does not appear to be deployed, highlight your HelloWorldApp application and click Deploy.

Step 7: Testing Your Web Application

You can test your Web application by typing the following URL in your Web browser:

http://<machine_name>:7001/HelloWorldApp

where machine_name specifies your WebLogic Server's DNS name or IP address. This URL should launch your Welcome page, as shown in Figure 3.16.

Figure 3.16Figure 3.16 The Welcome page of your HelloWorldApp application.

Click the Click here link to invoke your MyServlet servlet to display the Hello World! HTML page. Alternatively, you can invoke it by using the following URL:

http://<machine_name>:7001/HelloWorldApp/Myserlet

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020