EJB & JSP: Java On The Edge, Unlimited Edition by Lou Marco ISBN: 0764548026 Your Guide to Cutting-Edge J2EE Programming Techniques. Using JSPs with Servlets You ve learned about JSP pages containing Java code that gets passed to servlets. You ve witnessed JSPs using JavaBeans. You ve seen examples of JSP custom-tag libraries. By now, you ve discovered quite a lot about JavaServer Pages. But is there anything in the realm of generating dynamic Web content that JSPs cannot do? More specifically, does a situation exist in which using only JSPs to generate dynamic Web content is not the best solution? JSP development assumes that your pages have a common presentation style and theme. JSPs may be inadequate at providing dramatically different looks based on different user inputs or different data. A JSP page that effectively displays data as an HTML table may do a poor job displaying data as an animated chart. Then what is one to do? Although opinions may differ, you can leverage servlets to help your JSP page development in some situations. A servlet may start the dynamic content preparation process and then forward the request to one or more JSPs to complete the presentation. In the Model 2 approach, the Model-View-Controller pattern is applied to this situation by having a servlet act as the controller, the beans as the model, and the JSPs as the view. A more recent point of view embraces the idea of a server acting as a dispatcher of requests to JSPs and other Java container objects, such as Enterprise JavaBeans. Appropriately, the term used to describe the above-cited point of view is called the Dispatcher approach, which is illustrated in Figure 8-2. Figure 8-2: A servlet acting as a dispatcher As Figure 8-2 shows, the servlet captures the request and manages the application flow. The dispatching servlet may not be responsible for generating any dynamic presentation content. Figure 8-2 shows the dispatching servlet
We offer quality web hosting with only $3.99 per month with unlimited email addresses, unlimited bandwidth, and unlimited server space. Check our web hosting unlimited bandwidth section.