29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.1.3 Servlets in an enterprise application<br />

An enterprise application contains many components. It is important to specify<br />

the role of each of the components to understand how to use them in an<br />

application. Earlier, in 2.3, “Determine the application-flow architecture” on<br />

page 26, we discussed the architecture models for application design.<br />

Depending on the architecture you choose, it is important to understand the roles<br />

that servlets should play.<br />

The role of servlets in a Model 1 architecture<br />

You will generally see Model 1 architecture used in the more simple,<br />

straightforward applications. The bulk of the application is consumed with<br />

presenting data to the user. JSPs are well suited for this and simpler to use than<br />

servlets, so it follows that you will see more JSP use in a Model 1 type application<br />

than you will servlets. There may be situations when servlets are more<br />

appropriate due to the complexity of a task but you will probably not make<br />

extensive use of servlets in a Model 1 application.<br />

Of course, you have to remember that eventually a JSP becomes a servlet at<br />

execution time.<br />

The role of servlets in a Model 2 architecture<br />

If you remember back to the discussion of Model 2 architecture, the application<br />

components were divided into three categories: Model, view, and controller.<br />

Servlets in the controller layer<br />

The role of a servlet is to handle a request from a client and to generate the<br />

output. To do these tasks, a servlet will communicate with other components<br />

such as EJBs for the business logic and JSPs for the presentation of the output.<br />

Servlets are the link between the client request and the model. They must<br />

interface with the components performing the business logic of the application.<br />

Typically, a servlet will have to transform a client request in an object that is<br />

understandable for the model. It also determines which components are required<br />

to perform the request and call these components.<br />

Once the business logic is performed, the servlet will have to interface with the<br />

presentation layer, providing an object used to generate the output. So the<br />

servlet also manages the link between the model and the presentation and may<br />

decide to delegate the output to an HTML page.<br />

220 <strong>IBM</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> - Express V5.0.2 Developer Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!