SERVLETS AND THE J2EE ENVIRONMENT

 

 

The JavaTM 2 Platform, Enterprise Edition (J2EE) defines the standard for developing multitier enterprise applications.

 

J2EE simplifies enterprise applications by basing them on standardized, modular components, by providing a complete set of services to those components, and by handling many details of application behavior automatically, without complex programming.

 

However, multitier applications are hard to architect. They require bringing together a variety of skill-sets and resources, legacy data and legacy code.

 

In today's heterogeneous environment, enterprise applications have to integrate services from a variety of vendors with a diverse set of application models and other standards.

 

Industry experience shows that integrating these resources can take up to 50% of application development time.

 

Another advantage of J2EE is that the application model encapsulates the layers of functionality in specific types of components. Business logic is encapsulated in Enterprise JavaBeansTM (EJB) components.

 

And client interaction can be presented through plain HTML web pages, through web pages powered by Java technology-based applets, Java Servlets API, or JavaServer PagesTM technology, or through stand-alone Java applications.

 

Components communicate transparently using various standards: HTML, XML, HTTP, SSL, RMI, IIOP, and others.

Reusable J2EE components mean competitive choices for enterprise developers and IT organizations.

J2EE will enable them to assemble applications from a combination of standard, commercially available components and their own custom components.

From general business application components to vertical market solutions, a range of standardized Java 2 Enterprise Edition functionality is expected to be available off the shelf.

This means that an e-commerce site could be built using a combination of off-the-shelf EJB components for shopping cart behaviors, modified EJB components for specialized customer services, and completely customized layouts using JavaServer Pages technology that bring a unique look and feel to the site.

This approach means faster development time, better quality and maintainability, and portability across a range of enterprise platforms.

The bottom line benefits are increased programmer productivity, better strategic use of computing resources, and greater return on an organization's technology investments.

 

 

This is the ultimate J2EE architecture, full blown. There can be many variations.

 

As long as there are 3 – tiers.

 

Terms to know:

·       As much as you can about object oriented design

·       Client/server computing

·       Plug-ins

·       Scripting languages

·       Java

·       ActiveX

·       Security

·       Internet vs. intranet

·       Server side programming

·       Application programming

Time to start thinking about “the big project”.

 

Phase 0: Make a plan

 

·       Define your objects and the interfaces between them

·       Pick your platform (Borland, websphere, etc)

·       Do one more warmup assignment

 

Phase 1: Write a project spec. I will give you some of my own specs in another document. You will have to work on the next “warm up” assignment and the project spec at the same time, although the spec is due two weeks later than the program.

 

The program will be “reusable” in your project (most likely) if you use servlets.

 

The architecture of the servlet API is that  of a classic service provider a service() method through which all client requests will be sent by a servlet container software, and life cycle methods is loaded and unloaded (this rarely happens rarely).

 

public interface Servlet {

   public void init (ServletConfig config)

       throwsServletExceptioin;

   public ServletConfig getServletConfig();

   public void service (ServletRequest req,

          ServletResponse res)

          throws ServletException, IOException;

   public String getServletInfo();

   public void destroy;

}

 

getServletConfig()’s sole purpose is to return a ServletConfig object that contains initialization and startup parameters for this servlet. getServletInfo() returns a string containing information about the servlet, such as author, version and copyright.

ServletsRule is about as simple as a servlet can get. The servlet initialized only once by calling ins init() method, on loading the servlet after the servlet container is first booted up. When a client makes a request to a URL that happens to represent a servlet, the servlet container intercepts this request and makes a call to the service() method, after setting up the HttpServletRequest and HttpServletResponse objects.

 

//Servlets.java

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

 

public class ServletsRule extends HttpServlet {

  int I = 0;  // servlet “persistence”

  public void service (HttpServletRequest req,

  HttpServletResponse res) throws IOException {

     res.setContentType (“text/html”);

     PrintWriter out = res.getWriter();

     out.print(“<HEAD><TITLE”>

     out.print(“<A server-side strategy”);

     out.print(“</TITLE></HEAD><BODY>”;

     out.print(“<h1>Servlets Rule! “ + i++

     out.print(“</h1></BODY>”

     out.close();

    }

 

}