Including Other Files

Splitting your code is one of the first techniques you can use to organize it. Many sites have a consistent header on every page. You can put the header into a separate file and include it in every page. When you need to change the header, you only need to change one file.

Within a Java Server Page, you can choose to include another file at page compile time or at runtime. The advantage of including a file at compilation time is performance. At runtime, the JSP engine doesn't need to do any work because the file has already been included. Unfortunately, the servlet engine can only include files at runtime. After all, you are the one who compiles the server—how could the servlet engine include something at compile time?

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.