[ Team LiB ] Previous Section Next Section

When to Use Servlets

Servlets play an important role in providing the necessary infrastructure for integrating Web applications with enterprise components built using J2EE components such as EJBs, JMS, and so on. Servlets can be used on their own to implement small- to medium-scale applications.

HTTP servlets, the most popular implementation of servlets, provide the abstraction necessary for HTTP requests to access the underlying business components in an enterprise scenario. The HTTP servlets provide the framework for creating interactive applications for client presentation (usually in a Web browser), while other WebLogic Server components handle the necessary business logic. WebLogic Server HTTP servlets have access to the other components, such as JDBC connection pooling, Jolt connection pooling, EJBs, and JMS. Along with JSP, servlets can be effectively used to generate static or dynamic HTML, thereby providing an excellent application framework in an n-tier architecture.

As an MVC Controller

The Model-View-Controller (MVC) architecture extracts maximum benefits from the combined power of JavaServer Pages (JSP) and servlets. For example, Struts, an Apache Web application framework implementation, uses servlets as an effective controller and, with JSP, provides an excellent framework for developing Web applications. In the MVC design pattern, HTTP requests are sent to the servlet, which serves as the controller and dispatches the requests to the appropriate business handler that embeds the business logic. The controller receives the response from the handler when the request is processed, and again determines the appropriate view and displays it.

NOTE

As we go through one of the most important uses of servlet, it's good to note that servlets should not be used for producing a lot of HTML output. Servlets should be used in conjunction with JSP, which we'll cover later in the book in great detail. For now, because our servlets are small and simple, we'll use them to render the HTML output.


As a Session Tracker

HTTP servlets provide the necessary APIs for storing state management information for conversations between a client and the WebLogic Server, such as in a shopping cart example. The first invocation of a servlet from a client—for example, a login request—creates the session and the other application servlets used to update the session during the course of the conversation.

    [ Team LiB ] Previous Section Next Section