1.3.2. Web UIs and Components
The J2EE framework supports web interfaces with the concept of web components. These
components run within application servers and take advantage of several runtime services
provided by these servers, including user session management, security services like
authentication and encrypted communications, and so on. Web components are also able
to access other J2EE resources and components, such as Java Database Connectivity
(JDBC) DataSources and local and remote EJB components.
J2EE supports the development of web components and web UIs with a family of three
standards: Java servlets , JavaServer Pages (JSPs) and, more recently, JavaServer Faces
(JSF). Each of these supports different programming models and runtime models, and
each is important in different ways and in different contexts. Struts, a nonstandard but
popular web interface technology, is described in a later section.
220.127.116.11. Java servlets: Basic web-enabled components
A servlet is a Java object that runs within a server to provide a service to a client. The name
"servlet" was originally meant to be a takeoff on "applet"—a servlet can be thought of,
roughly, as a server-side applet. The Java Servlet API (JSR 053 and JSR 154) provides a
generic mechanism for extending the functionality of any kind of server that uses a protocol
based on requests and responses.
For the most part, servlets are used behind web servers for dynamic generation of HTML
content. But more generally, a servlet is a Java object that can receive HTTP requests and
provide HTTP responses. The most typical scenario is a web browser that issues a request
to a web server and a Java servlet that receives the request, performs some operations
(perhaps JDBC calls to retrieve information or a call to an EJB component to invoke some
business logic), and sends an HTML response back to the browser. But servlets can also
serve in other ways in an enterprise application. A remote application can issue an HTTP
request to a servlet, and the servlet can respond with an XML document in response, for
A key advantage of servlets over some other similar technologies, such as Microsoft Active
Server Pages, is that servlets are portable among operating systems and among application
servers. The advantage of servlets over some script-based web technologies, like Perl CGIs,
is that servlets are also compiled objects that are persistent between invocations, which
gives them major performance benefits over parsed scripts. Servlets also have full access
to the rest of the Java platform, so features such as database access are automatically
The Servlet API is a standard extension to the Java platform and is part of the J2EE
specifications. The API is implemented in the javax.servlet and
javax.servlet.http packages. The javax.servlet package defines classes that
represent generic client requests and server responses, while the
javax.servlet.http package provides specific support for the HTTP protocol,
including classes for tracking multiple client requests that are all part of a single client
18.104.22.168. JavaServer Pages (JSPs): Dynamic web pages
JavaServer Pages (JSPs) (JSR 053 and JSR 152) are also part of the J2EE specifications
family and closely related to Java servlets. You can think of JSPs as an alternative approach
to creating servlets, in one sense. JSPs are similar to alternative technologies such as PHP
and Microsoft Active Server Pages—they all provide a way to insert dynamic elements
directly into HTML pages.
In the case of JSPs, these dynamic elements invoke Java code using references and calls to Java beans, using custom tags that act as dynamic macros that are implemented by Java beans, or using raw Java code snippets. Chapter 4 provides details on writing JSPs. In addition, this chapter provides some details on using the Java Standard Tag Library (JSTL), a standard set of handy JSP tags that can be used in any compliant JSP engine.
22.214.171.124. JavaServer Faces (JSF): Web UI components
JavaServer Faces (JSR 127) is a recently released Java standard for user interface (UI)
components. JSF builds on the foundation provided by Java servlets and JSPs, providing
a UI component model based on JSP tags.
This UI component model allows you to create UIs for your application from a set of predefined components (similar to the role that Java Swing plays in the world of desktop GUIs). The JSF model also includes state management and page navigation facilities that help in the development of applications using customary design patterns like model-view-controller (MVC).
See Chapter 5 for a short tutorial on JSF, its tag libraries, and application configuration