Chapter 6. Technology options 115
is usually represented to the View and the Controller with a set of JavaBean
components.
򐂰 The View is a visual representation of the model. Multiple views can exist
simultaneously for the same model, and each view is responsible for making
sure that it is presenting the most current data by either subscribing to state
change events or by making periodic queries to the model. With J2EE, the
view is generally implemented using JavaServer Pages (JSP).
򐂰 The Controller decouples the visual presentation from the underlying
business data and logic by handling user interactions and controlling access
to the model. It processes the incoming HTTP requests and invokes the
appropriate business or UI logic. Using J2EE, the controller is often
implemented as a servlet.
Given its wide spread acceptance, there are several design frameworks
supporting the implementation of the Model-View-Controller pattern. These
include the Java Server Faces (JSF) Framework, Apache Jakarta Project’s
Struts, and IBM Global Services’s EAD4J.
6.3.1 Java servlets
Servlets are Java-based software components that can respond to HTTP
requests with dynamically generated HTML. Servlets are more efficient than CGI
for Web request processing because they do not create a new process for each
request.
Servlets run within a Web container as defined by the J2EE model and, therefore
have access to the rich set of Java-based APIs and services. In this model, the
HTTP request is invoked by a client such as a Web browser using the servlet
URL. Parameters associated with the request are passed into the servlet through
the HttpServletRequest, which maintains the data in the form of name/value
pairs. Servlets maintain state across multiple requests by accessing the current
HttpSession object, which is unique per client and remains available throughout
the life of the client session.
Acting as an MVC Controller component, a servlet delegates the requested tasks
to beans that coordinate the execution of business logic. The results of the tasks
are then forwarded to a View component, such as a JSP, to produce formatted
output.
One of the attractions of using servlets is that the API is a very accessible one for
a Java programmer to master. The specification of the J2EE 1.4 platform
requires Servlet API 2.4 for support of packaging and installation of Web
applications.

Get Patterns: Implementing Self-Service in an SOA Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.