O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Dynamically Including Content in Servlets and JSPs

Introduction

Servlets and JSPs often include fragments of information that are common to an organization, such as logos, copyrights, trademarks, or navigation bars. The web application uses the include mechanisms to import the information wherever it is needed, since it is easier to change content in one place then to maintain it in every piece of code where it is used. Some of this information is static and either never or rarely changes, such as an organization’s logo. In other cases, the information is more dynamic and changes often and unpredictably, such as a textual greeting that must be localized for each user. In both cases, you want to ensure that the servlet or JSP can evolve independently of its included content, and that the implementation of the servlet or JSP properly updates its included content as necessary.

This chapter recommends recipes for including content in both servlets and JSPs under several conditions:

  • When the included information is refreshed every time a user makes a request.

  • When the included information involves two or more nested levels—for example, when an included file in turn includes another piece of information, and so on.

  • When you want to use the deployment descriptor to update the item that a servlet includes, which is a handy, less error-prone way of including content when the content is configurable and changes rather often.

  • When you want to import resources into a JSP from outside ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required