The J2EETM Tutorial
Home
TOC
PREV TOP NEXT Search
Feedback

Updating Web Components

During development, you will often need to make changes to web components. To update a servlet you modify the source file, recompile the servlet class, update the component in the WAR, and redeploy the application. Except for the compilation step, you update a JSP page in the same way.

To try this feature, first build, package, and deploy the JSP version of the Hello application:

  1. Go to j2eetutorial/examples/src and build the example by running ant hello2.
  2. Create a J2EE application called Hello2App.
    1. Select File->New->Application.
    2. In the file chooser, navigate to j2eetutorial/examples/src/web/hello2.
    3. In the File Name field, enter Hello2App .
    4. Click New Application.
    5. Click OK.
  3. Create the WAR and add the greeting web component and all of the Hello2App application content.
    1. Invoke the web component wizard by selecting File->New->Web Component.
    2. In the combo box labelled Create New WAR File in Application select Hello2App. Enter Hello2WAR in the field labeled WAR Display Name.
    3. Click Edit to add the content files.
    4. In the Edit Contents dialog, navigate to examples/build/web/hello2. Select greeting.jsp, response.jsp, and duke.waving.gif, and click Add. Click OK.
    5. Click Next.
    6. Select the JSP radio button.
    7. Click Next.
    8. Select greeting.jsp from the JSP Filename combo box.
    9. Click Finish.
  4. Add the alias /greeting for the greeting web component.
  5. Specify the context root hello2.
  6. Deploy Hello2App.
  7. Execute the application by pointing a web browser at http://<host>:8000/hello2/greeting. Replace <host> with the name of the host running the J2EE server.

Now modify one of the JSP files. For example, you could replace the contents of response.jsp with:

<h2><font color="red">Hello, <%=username%>!</font></h2>
 

Thus, to update the file in the WAR and redeploy the application:

  1. Edit response.jsp
  2. Execute ant hello2 to copy the modified file to the build directory.
  3. Select Hello2App.
  4. In the deploytool, select Tools->Update Files.
  5. A dialog appears reporting the changed file.Verify that response.jsp has been changed and dismiss the dialog.
  6. Select Tools->Deploy. Make sure the checkbox labeled Save object before deploying is checked.

You can also perform steps 4. through 6. by selecting Tools->Update and Redeploy. The deploytool replaces the old JSP file in Hello2App.ear with the new one and then redeploys the application.

When you execute the application, the color of the response should be red:

Figure 22    Red Response

Home
TOC
PREV TOP NEXT Search
Feedback