Java
  Home arrow Java arrow Page 4 - J2EE Essentials
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

J2EE Essentials
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2005-09-29

    Table of Contents:
  • J2EE Essentials
  • Multi-Tier Architecture
  • Vendor Independence
  • Java Servlets
  • Enterprise JavaBeans
  • Web Services
  • 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


    J2EE Essentials - Java Servlets


    (Page 4 of 7 )

    You are no doubt familiar with accessing simple, static HTML pages using a browser that sends a request to a web server, which in turn sends back a web page that’s stored at the server. In that role, the web server is simply being used as a virtual librarian that returns a document based on a request.

     

    That model of serving up static web pages doesn’t provide for dynamically generated content, though. For example, suppose that the web client wants the server to return a list of HTML documents based on some query criteria. In that case, some means of generating HTML on the fly and returning it to the client is needed.

     

    A servlet is a Java component implementing the javax.servlet.Servlet interface. It gets invoked as a result of a client request for that particular servlet. The servlet model is pretty generic and not necessarily bound to the Web and HTTP, but nearly all of the servlets that you’ll encounter will fall into that category. The web server receives a request for a given servlet in the form of an HTTP query. The web server in turn invokes the servlet and passes back the results to the requesting client. The servlet can be passed parameters from the requesting web client. The servlet is free to perform whatever computations it cares to, and spits out results in the form of HTML back to the client.

    The servlet itself is managed and invoked by the J2EE servlet container. When the web server receives the request for the servlet, it notifies the servlet container, which in turn will load the servlet as necessary, and invoke the appropriate javax.servlet.Servlet interface service method to satisfy the request.

    If you’ve done any web application programming using CGI (common gateway interface), you’ll be familiar with the limitations of that mechanism including lack of portability and no intrinsic support for session management (a much-overused example is the ability to maintain a list of items in a virtual shopping cart). If you’ve not done any development using CGI, consider yourself lucky and take my word for it—life with J2EE is a whole lot better! Java servlets are portable, and as you will see in later chapters, the servlet containers provide support for session management that allows you to write complex web-based applications. Servlets can also incorporate JavaBean components (which share little more than a name with Enterprise JavaBeans) that provide an additional degree of application compartmentalization.

    JavaServer Pages

    JavaServer Pages, like servlets, are concerned with dynamically generated Web content. These two web components comprise a huge percentage of the content of real-world J2EE applications.

    Building servlets involves building Java components that emit HTML. In a lot of cases that works out well, but isn’t very accessible for people who spend their time on the visual side of building web applications but don’t necessarily care to know much about software development. Enter the JavaServer Page. JavaServer Pages are HTML-based text documents with Java code with scriptlets—or chunks of Java code—embedded into the HTML document within XML tags.

    When JSPs are deployed, something pretty remarkable happens—the contents of the JSP are rolled inside out like a sock, and a servlet is created based on the embedded tags and Java code scriptlets. This happens pretty much invisibly. If you care to, you can dig under the covers and see how it works (which makes learning about servlets all the more worthwhile):

     

    You may have had some exposure to JavaScript—that’s a Java-like scripting language that can be included within a web page, and is executed by the web browser when a page containing JavaScript code is browsed to by the user. JSP is a little like that, but the code is compiled and executed at the server, and the resulting HTML is fed back to the requesting client. JavaServer Pages are lightweight and fast (after the initial compilation to the servlet), and provide a lot of scaleability for web-based applications.

    The developer of a JavaServer Page can create both static and dynamic content in a JSP. Because content based on HTML, XML, etc. forms the basis of a JSP, a non-technical person can create and update that portion of a page. A more technical Java developer can create the snippets of Java code that will interface with data sources, perform calculations, and so on—the dynamic stuff.

    Since an executing JSP is a servlet, JSP provides the same support for session management as servlets. JSPs can also load and call methods of JavaBean components, access server-based data sources, or perform complex calculations at the server.

    JSPs are introduced in detail in Chapter 3. Chapter 4 continues with more advanced JSP concepts.

    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 taken from chapter one of the book Beginning J2EE 1.4 From Novice to Professional, written by James L. Weaver, Kevin Mukhar, and Jim Crume (Apress, 2004; ISBN: 1590593413). Check it out at your favorite bookstore. 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 5 Hosted by Hostway
    Stay green...Green IT