Introduction: This article is the first part of the new JSP Best Practices series, which describes the JavaServer Pages include mechanism. Follow the Java programming expert Brett McLaughlin Learn how to use include to add static header and footer files to your Web site or Web application page.
Welcome to the latest best practices series in the Java area. If you've seen a series of previous articles, you'll know that best practices are designed to give you a quick look at useful aspects of various Java technologies. This series of best practices deals specifically with JavaServer Pages (JSP) technology, which is one of the core Java EE technologies.
In short, JSP technology is a tool for building Web pages or Web application interfaces on a Java platform. JSP technology allows us to do the following things: Dynamic response request data, display complex XML and HTML, and create lively and interesting, dynamic-driven Web sites. In this series, you'll learn the basics of building a Web site with JSP technology. I'll introduce you to the most commonly used JSP mechanisms, where you'll learn about basic WEB development technologies, such as making templates, manipulating dynamic content, image hosting, creating a library of utility code, and so on.
This is the first of a series of articles, and in this article we will focus on the JSP include mechanism, which allows us to "pull" the contents of the local HTML page. We'll start with some background information on Web page include development, especially the use of framework and server-side include. Then, I'll show you how to use the JSP include mechanism to add a unified header file and footer file to a Web page or Web application screen.
A better look
Creating a consistent design and layout for your Web pages is one of the easiest ways to ensure a professional look. You may have seen enough sites to know that most of the pages in a single site share a common page header, footer, and some kind of navigation bar. On well-designed sites, these elements will render the same layout, content, and functionality on each page, and the main panel (often called the content pane) will change with each view.
Previously, this layout was almost entirely implemented by the framework and frameset. Each piece of static content is placed in a frame, and the main content of the page is placed in the middle frame. The trouble with the framework is that different browsers often display them in different ways, making them look inconsistent. Using frames to link external sites from internal pages is more difficult than you might think. It was intended to allow users to view external content without leaving the site, but the results were often inconsistent. The user ultimately sees the entire site being squeezed into a much smaller framework, and, worse, your site will eventually be nested within another site framework. This confusion drives Web designers to find a better solution. Server-side include (Server-side Include,ssi) is a.
Server-side Include
Not long ago, SSI was one of the most popular options for creating shared content. A simple SSI pseudo directive allows you to create a page that contains another page's content, such as headers and footer files, as shown in Listing 1.
Listing 1. The SSI being used
<title>Simple SSI test</title>
<body>
This content is statically in the main HTML file.<br />
<!--#include virtual="included.html" -->
</body>
We will soon use this file to do an exercise. Currently, you should save it as a test-ssi.shtml. In most settings, SSI files must end with. shtml, which enables the WEB server to know to parse them into SSI pseudo directives. Listing 2 shows the contents of the include file named Included.html.