Home arrow Java arrow Page 4 - J2EE Essentials
JAVA

J2EE Essentials


This article provides a high-level introduction to J2EE. It 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).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 12
September 29, 2005
TABLE OF CONTENTS:
  1. · J2EE Essentials
  2. · Multi-Tier Architecture
  3. · Vendor Independence
  4. · Java Servlets
  5. · Enterprise JavaBeans
  6. · Web Services
  7. · Summary

print this article
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
JAVA ARTICLES

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

Developer Shed Affiliates

 




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