Tomcat-based Web Applications

Up

web application
end-user software accessed via a web client
J2EE
Java 2 Enterprise Edition. Provides framework necessary for building and running distributed, multitier applications that can scale from small to large situations

J2EE based on 3-tiered model

  1. client; e.g., web browser, stand-alone application, mobile device
  2. middle (or logic); e.g., J2EE platform with Tomcat Web Container running Web applications and EJB container with business objects
  3. EIS (Enterprise Information Systems); e.g., databases, data file, other back-end services, legacy systems
J2EE service
Implementation of a server that conforms to the J2EE specification. Two most basic are Web server (or Web container) and business object server or EJB container

J2EE Interfaces

JDBC
Java Database Connection. Provides SQL interface to external databases
JTA
Java Transaction API. Provides interface to transaction services
JNDI
Java Naming and Directory Interface. Provides interface to naming and directory services like LDAP, DNS, and NIS (Network Information Name Service)
J2EE Connector Architecture
API for interfacing to external EIS systems, including legacy systems
JAXP
Java API for XML processing
JavaMail
API for accessing mail servers
JAF
API for Java Beans for constructing applications and manipulating component functionality
JMS
API for acessing messaging services
JAAS
Java Authentication and Authorization Service
RMI-IIOP
API for acessing remote services over a common protocol

Current J2EE spec is version 1.4 (Nov 2003)

reference implementation
an actual implementation of a spec so developers know how it is supposed to work.
web container
J2EE service responsible for running Web applications. Tomcat is the most widely used.
web application
Comprised of JSP's and servlets (and JSP's get turned into servlets by the container), and static files. It is packaged as a single archive file or directory that is described as a unit by the web descriptor file web.xml. So from the web container's perspective, any directory that contains a root subdirectory WEB-INF with the web.xml descriptor file is considered a web application. The web container creates an object that represents the web application. In Tomcat these are contexts and are represented by the <Context> tag.
servlet
a unit of code that takes an HTTP request and returns an HTTP response. The servlet can handle all its processing internally or can rely on external services that are accessed by the defined J2EE interface.
JSP
a servlet skeleton that the Web container converts to a servlet at runtime
scope
The layer on which an operation is taking place.

Basic Objects

The documentation for the full list of J2EE objects is available here.

HttpServlet
The basic sevlet object extended by any servlet you write. There are five stages in its lifecycle:
StageMeaning
InstantiationWhen the web container calls new on its class
InitializationWhen the init method is called. Startup functions can be performed
ServiceReady for use. The doPost, doGet, doDelete, etc. methods are called
DestructionThe destroy method is called
FinalizationThe object is garbage-collected by the JVM

There are 7 methods used to access a servlet during its Service stage:

  1. doDelete
  2. doGet
  3. doHead
  4. doOptions
  5. doPost
  6. doPut
  7. doTrace

These methods map to various HTTP request types. Each takes two parameters, an HttpServletRequest for the request and an HttpServletResponse for the response.

You can implement the service method, which takes the same parameters, and it will be called by the framework. The init (which takes a ServletConfig argument) can be used, for example, to connect to legacy services and the destroy method can free up that connection.

ServletConfig
represents the configuration of the servlet and can be accessed through the getServletConfig() method.
ServletContext
represents the Web container's configuration and can be used by the servlet to access the log method of the Web application.
HttpServletRequest
wrapper for an HTTP request
HttpServletResponse
Provides and OutputStream to send info back to client, along with headers, cookies, encoding, etc.
HttpSession
Encapsulates state. Can be accessed through the getSession method of the HttpServletRequest object.
enterprise Web application
relies on services such as LDAP authentication, database servers, legacy systems, etc.


Page last modified on October 06, 2005, at 04:56 PM