You can implicitly include preludes and codas for a group of JSP pages by adding items to the Include Preludes and Codas lists. Their values are context-relative paths that must correspond to elements in the web application. When the elements are present, the given paths are automatically included (as in an include directive) at the beginning and end, respectively, of each JSP page in the property group. When there is more than one include or coda element in a group, they are included in the order they appear. When more than one JSP property group applies to a JSP page, the corresponding elements will be processed in the same order as they appear in the JSP configuration section.
For example, the Duke’s Bookstore application uses the files /template/prelude.jspf and /template/coda.jspf to include the banner and other boilerplate in each screen. To add these files to the Duke’s Bookstore property group using the deployment descriptor, follow these steps:
In NetBeans IDE, expand your project’s folder in the Projects pane.
Expand the Web Pages node and then the WEB-INF node.
Double-click web.xml to open it in the editor pane.
Click Pages at the top of the editor pane.
Add a new JSP property group if you haven’t already (see Setting Properties for Groups of JSP Pages) and give it the name bookstore2 and the URL pattern *.jsp.
Expand the JSP Property Group node.
Click the Browse button to the right of the Include Preludes field to locate the file that you want to include at the beginning of all pages matching the pattern in the URL pattern field. In this case, you want the /template/prelude.jspf file.
Click the Browse button to the right of the Include Codas field to locate the file that you want to include at the end of all pages matching the URL pattern. In this case, you want the /template/coda.jspf file.
Instead of performing the preceding steps, you can add preludes and codas by editing the XML by hand using NetBeans IDE by doing the following:
Perform steps 1 through 3 in the preceding set of steps.
Click XML at the top of the editor pane.
Add a new JSP property group (see Setting Properties for Groups of JSP Pages) and give it the name bookstore2 and URL pattern *.jsp.
Add an include-prelude element to the jsp-property-group element and give it the name of the file to include, in this case, /template/prelude.jspf.
Add an include-coda element to the jsp-property-group element and give it the name of the file to include, in this case, /template/coda.jspf.
Preludes and codas can put the included code only at the beginning and end of each file. For a more flexible approach to building pages out of content chunks, see A Template Tag Library.