In order to allow users to browse through your catalog of products, you need to create pages that display information about the various categories and products you sell. You could create a separate Java Server Page for every single product, but clearly this would be extremely inefficient. Each time a new product was created or removed from your catalog, modifications would have to be made.

For Pioneer Cycling, we created generic template pages for products and product categories. These template pages are simply Java Server Pages that display general information about one category or one product.

These pages are general and data-driven; they are not hard-coded for a specific product or category. All of the information displayed on them comes from the repository. These general, dynamic pages are convenient because once written, they can typically be used to display any category or any product in a product catalog. For example, a very simple site could have one category template page file and one product template page file. Because these pages are dynamic, they are easy to maintain. As you add more products to your repository, you don’t necessarily have to change the product catalog template pages.

However, you may decide to display different information about one category of products than another. For example, in the Pioneer Cycling Store, we display slightly different information for bikes than for all other products. On the bike template page, we included a Compare to Other Products button that brings up a form that allows users to compare the features of one bike to another. We did not want this button to appear for other products. For this reason, we created several template pages in the Pioneer Cycling code: product_generic.jsp, product_bike.jsp, product_part.jsp, product_bundle_jsp, and product_gift_certificate.jsp. Most products use the product_generic.jsp template file; only bikes use the product_bike.jsp template file. However, because much of the template page content is similar for the two template pages, lots of the supporting code is pulled out into various JSP code fragment files, which can be inserted in the body of a JSP file (using the dsp:include tag or JSP’s include directive). This makes your template pages easier to maintain.

By creating page fragments and using the dsp:include tag or JSP’s include directive to embed them in other pages, you can reuse JSP code and simplify the page development process. However, extensive use of this technique slows down site performance slightly. See Appendix B: Optimizing Performance for more information on reusing code. In this case, we used the dsp:include tag syntax in moderation, but did not avoid it entirely.

Template Page File Name in database

Every category and product in the repository has a template.url database value that defines the template page to use to display this product or category.

The template page (that is, the template.url value) for all bike products is:

<ATG2007.3dir>/PioneerCyclingJSP/j2ee-apps/pioneer/
web-app/
en/catalog/product_bike.jsp.

The template page for all other products is:

<ATG2007.3dir>/PioneerCyclingJSP/j2ee-apps/pioneer/
web-app/
en/catalog/product_generic.jsp.

Later, if we decided to display certain products (such as bike helmets) using a totally different template page, we could create a third template page, and modify the template.url value for all helmets in the database to reference the new template page name.

In Pioneer Cycling, all the catalog media files (templates and images) are stored on the file system and the URLs for accessing those files are stored in the repository. It is also possible to use the repository item types media-internal-binary and media-internal-text to store images and text in the repository.

 
loading table of contents...