JSP Templates
Including Files in JSP Pages
Concepts
- The include directive.
Including Files at Page Translation Time: The include Directive
<%@ include file="template-example-footer.jsp"%>
- This will add the contents of the page in the file attribute to the JSP file at Translation time.
Simple Example of Including Files
- Since you can
include
the contents of other files when JSP files are converted to servlets, this allows us to create a simple template system for JSP. - Example:
A Simple Template System for JSP Pages
-
Take a typical HTML page and slice it up into segments based on tags.
-
Put each segment into its own file.
-
Then replace each tag with a JSP include statement.
Warning
Don’t split a tag up into multiple files.