Java
  Home arrow Java arrow Page 3 - 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 - How it works


    (Page 3 of 4 )

    Before we look at what we've done in this example, you should stop the J2EE server by selecting the following option from the Windows Start menu:

    Start | All Programs | Sun Microsystems | J2EE 1.4 SDK | Stop Default Domain

    How It Works

    The JSP file that you created is a text file that consists of HTML and embedded snippets of code. Notice in this file that there are tags with enclosed Java code, as we discussed in Chapter 1:

    <%--
        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>

    When the JSP is compiled into a servlet, that servlet code expands the JSP's code snippets and HTML into code that writes HTML to an output stream:

    out.write("\n\n");
    out.write("<html>\n");
    out.write("<head>\n");
    out.write(" <title>Hello World - test the J2EE SDK installation");
    out.write(" </title>\n");
    out.write("</head>\n");
    out.write("<body>\n");
    for (int i = 1; i < 5; i++)
    {
     
    out.write("\n  ");
      out.write("<h");
      out.write(String.valueOf(i));
      out.write(">Hello World");
      out.write("</h");
      out.write(String.valueOf(i));
     
    out.write(">\n");
    }
    out.write("</body>\n");
    out.write("</html>\n");

    That code, when executed, will write the following HTML code to the stream that is sent back to the requesting browser:

    <html>
    <head>
      <title>Hello Hello World - test the J2EE SDK installation
      </title>
    </head>
    <body>
      
    <h1>Hello World</h1>
      
    <h2>Hello World</h2>
      
    <h3>Hello World</h3>
      
    <h4>Hello World</h4>
    </body>
    </html>

    That's how the JSP code works. The process of packaging and deployment has a few more steps. Let's dig in a bit and see what's happening:

    In order to deploy a J2EE application to a server, it has to be bundled up into an archive--that's a single file that packages up all the requisite files. The Web Archive (WAR) has to contain the components that we've created for the application (the JSP file), as well other support files. Those support files include a deployment descriptor that tells the server what's contained in the WAR and how to run it, a manifest for the archive, which is an application table of contents, and a file containing deployment information specific to the J2EE reference implementation server:

    Once those contents have been assembled into a WAR file, that WAR can then be deployed to the J2EE server. That process sends the archive to the server, which then reads the deployment descriptor to determine how to unbundle the contents. In the case of this application, it sees that the WAR contains a JSP, and so it compiles that JSP into a servlet.

    In order to run the application once it is deployed, you have to request the JSP by requesting an URL with your web browser. Notice that the URL consists of the protocol (http), the server name (localhost), the root context of the application (hello) and the requested resource (index.jsp):

    The server receives the incoming HTTP request, and uses the deployment information to invoke the appropriate servlet in a servlet container. The servlet writes HTML to an output stream, which is returned to the web browser by the server.

    Problems and Solutions

    If you run into any difficulties, the following table lists some common problems and how to fix them:

    Problem

    Solution

    Verifier reports errors.

    Carefully retrace your steps and ensure that the steps are followed correctly as described. 

    When testing the JSP, the web browser reports "Page cannot be displayed" when tryin to open the URL http://localhost:8080. 

    Make certain that there weren't any errors reported when starting the J2EE server.

    Make certain that you've specified port "8080" in the URL (this is the default port used by the J2EE server). 

     

    When testing the JSP, it reports a compilation error in the web browser.

    Double-check the code in index.jsp. If you've mistyped something, the server won't be able to compile the JSP. The message in the web browser should give you a hint where to look.
     

    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 3 Hosted by Hostway
    Stay green...Green IT