Home arrow Java arrow Page 2 - Getting Set with J2EE, conclusion

Getting Set with J2EE, conclusion

This article, the second of two parts, will take you through writing a simple application with J2EE 1.4 SDK. It is excerpted from chapter two of the book Beginning J2EE 1.4 From Novice to Professional, written by James L. Weaver, Kevin Mukhar, and Jim Crume (Apress, 2005; ISBN: 1590593413).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
December 15, 2005
  1. · Getting Set with J2EE, conclusion
  2. · Try it Out: Hello J2EE World
  3. · How it works
  4. · Summary

print this article

Getting Set with J2EE, conclusion - Try it Out: Hello J2EE World
(Page 2 of 4 )

  1. Create a directory on your machine that will be your sandbox for this exercise. I'll use C:\3413\Ch02 for mine.
  2. Create a new file in that directory called index.jsp using your favorite text editor. Here's the code for that file:

        file: index.jsp
        desc: Test installation of J2EE SDK 1.4
      <title>Hello World - test the J2EE SDK installation
      for (int i = 1; i < 5; i++)
      <h<%=i%>>Hello World</h<%=i%>>

  3. Start up the J2EE server if it's not already running, by following the instructions given above.
  4. Start the J2EE Deployment Tool application that comes with the J2EE SDK. This tool is a utility that is used to assemble application components into distributable archives, and also to distribute the application to the J2EE server. You can invoke this tool by choosing the following option from the Start menu:

    Start | All Programs | Sun Microsystems | J2EE 1.4 SDK | Deploytool

    When the Deployment Tool has finished initializing, you'll see its main window:


  5. We need to create a new Web Archive (WAR). A WAR file is an archive file that will contain the web components of a J2EE application, along with a descriptor or "table of contents" that describes what is in the archive. Web applications frequently consist of many more files than our simple application, and the WAR is a very convenient means of bundling up all of those files into a single file for deployment. Select File | New | Web Component from the menu. This will start the New Web Application Wizard:


  6. On the War File page of this wizard, shown above:

    • Make certain that the radio button labeled Create New Stand-Alone WAR Module is checked.
    • In the WAR Location text field, enter (or browse to) the path to your working directory, followed by hello.war (in my case,
      C:\3413\ch02\hello.war). This tells the Deployment Tool what to name the WAR file.
    • Enter Hello in the WAR Name field, which is the name that will be displayed in the Deployment Tool for this WAR file
    • Enter hello into the Context Root field. This sets what's called the "context root" (kind of a "home base") for your WAR file when it gets deployed to the server.

      You can think of the context root as sort of like a logical directory that's part of the URL. For example, a hypothetical web application located at www.apress.com/codesamples
      has a root context of "codesamples". Note that this doesn't necessarily correspond to a directory on the server called "codesamples" --it's a name that the server recognizes and maps to a specific application

      Next, click the "Edit" button on the right hand side of the dialog. This will open a dialog to select files to add to the Web Archive:


  7. In the dialog shown above, set the starting directory (using the top textbox) to your working directory. This simply points the dialog to where your application files are. You should see a folder tree with index.jsp appearing below your working directory folder. Select index.jsp and click the Add button. You should now see index.jsp in the Contents tree at the bottom of the dialog. Click the OK button to close this dialog. Click the Next button to go to the next page of the wizard: 
  8. You learned in Chapter 1 that there are several different kinds of components in J2EE. This particular application includes a JavaServer Page component, and this is where we tell the Deployment Tool what kind of component we're building. Select the radio button labeled JSP to indicate that you are creating a JavaServer Page component. Click on the Next button to go to the next page of the wizard:



    The Deployment Tools tree navigator now displays the Web Archive you've just created, and its contents.

    Save your work now. With the Hello WAR highlighted in the tree on the left, select File | Save All.

  9. The next step is to verify the WAR. This step will catch problems with bad code in the JSP, and make sure that the WAR doesn't have obvious problems before it's deployed to the server. Make sure the Hello WAR is still highlighted, and select Tools | Verify J2EE Compliance from the menu. This will bring up a window that will help you verify that your WAR complies with the J2EE specification.

    The Display group of radio buttons, shown above, lets you select how much detail you care to see about the tests that are run. If you want to only see messages about failures, select the radio button labeled Failures Only (try not to take it personally--it's not the best phrasing in the world). Click the OK button.

    If all went well, you should see a message at the bottom indicating that no tests failed. If your JSP had problems with its code, you will get compilation error messages. If you see compilation errors, go back to your JSP file and check it carefully to make sure it matches the code in the book.

  10. Were almost done. Next, we need to deploy the WAR to the J2EE server. With the hello WAR selected in the tree navigator, select Tools | Deploy from the menu. This will bring up the Deploy Module dialog:

  11. You'll supply the user name and password that you specified when installing the J2EE SDK 1.4. Click OK, and when the dialog closes a window will appear and will show the status of the deployment process. You should see something like:

    Wait until you see the Completed message, and click Close.

  12. It's time to test your first JSP. Start a web browser and open the following URL:


    After a couple of seconds, you should see the web page:

Congratulations! Your first JSP is a success!

blog comments powered by Disqus

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials