14.7. Reusing a Common Page Layout with SiteMesh
Problem
You want render your application's pages using a common layout without having to change your JSP pages or your application's Struts configuration.
Solution
Use SiteMesh to wrap your application's pages with a common layout and other presentation features.
Discussion
SiteMesh (http://www.opensymphony.com/sitemesh/) is a
web-page layout and decoration framework. It allows you to decorate
the web pages of an existing application with a common layout. It
provides similar features as Tiles but uses a completely different
approach. When you use Tiles, you adopt the Tiles-way of doing things
by constructing pages using Tiles custom JSP tags, creating
definitions in a Tiles configuration file, and linking actions to
Tiles using the TilesRequestProcessor. Tiles
becomes a pervasive part of your web application.
SiteMesh takes a different approach. It uses a servlet filter to modify the HTTP responses generated by your application, with responses typically generated by JSP pages. SiteMesh amends the response based on settings in a configuration file.
Suppose you have a site with three web pages: a main page, and two secondary pages. The main page looks something like Figure 14-5.

Figure 14-5. Page slated for decoration by SiteMesh
The secondary pages referred to by the two hyperlinks are, like this page, simple. The struts-config.xml file for this ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access