Java
  Home arrow Java arrow Page 2 - Getting Set with J2EE, conclusion
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Getting Set with J2EE, conclusion
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2005-12-15

    Table of Contents:
  • Getting Set with J2EE, conclusion
  • Try it Out: Hello J2EE World
  • How it works
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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
      --%>
      <html>
      <head>
        <title>Hello World - test the J2EE SDK installation
        </title>
      </head>
      <body>
      <%
        for (int i = 1; i < 5; i++)
        {
      %>
        <h<%=i%>>Hello World</h<%=i%>>
      <%
        }
      %>
      </body>
      </html>

    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
        /index.jsp
        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:

             http://localhost:8080/hello

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

    Congratulations! Your first JSP is a success!

    More Java Articles
    More By Apress Publishing


       · This article is an excerpt from the book "Beginning J2EE 1.4 From Novice to...
     

    Buy this book now. This article 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). Check it out at your favorite bookstore today. Buy this book now.

    JAVA ARTICLES

    - 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 ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT