

Templates are JSP files that include parameterized content. To minimize the impact of layout changes, we need a mechanism for including layout in addition to content that way, both layout and content can vary without modifying files that use them. If a Website has multiple pages with identical formats, which is common, even simple layout changes require modifications to all of the pages. However, because layout is hard coded, layout changes require modifications to the page. In the example listed above, content is included with the JSP include directive, which allows the content of the page to vary - by changing the included files - without modifying the page itself. The layout of the page shown in Figure 1 is implemented with HTML table tags:Įxample 1.

JSP does not provide direct support for encapsulating layout, so Webpages with identical formats usually replicate layout code for example, Figure 1 shows a Webpage containing header, footer, sidebar, and main content sections. In fact, layout managers demonstrate an example of one of the tenets of object-oriented design: encapsulate the concept that varies, which is also a fundamental theme for many design patterns. This article explores a template mechanism for JavaServer Pages (JSP) that, like layout managers, encapsulates layout so it can be reused instead of replicated.īecause layout undergoes many changes over the course of development, it's important to encapsulate that functionality so it can be modified with minimal impact to the rest of the application.

For example, traditional GUI toolkits provide layout managers, in one form or another, that allow layout algorithms to be encapsulated and reused.

Although Web development tools are rapidly progressing, they still lag behind most graphical user interface (GUI) toolkits such as Swing or VisualWorks Smalltalk.
