Example: A Standard Title Bar

One of the more frequent uses for the include directive is to easily establish a common look and feel for JSPs. You can do this by creating a standard navigation or title bar in a separate file that will be included in all of your JSPs. To further explain how this works, let's create our own title bar that includes a logo and the name of the user that is logged in. Listing 7.1 contains the JSP file we will be including.

Code Listing 7.1. titlebar.jsp
<table>
  <tr>
    <td>
      <img src="sams.gif">
    </td>
    <td>
      <%
        // Get the User's Name from the session
        out.println("<b>Hello: " + request.getParameter("user") + "</b>");
      %>
    </td>
  </tr>
</table>

You can see that this is a simple JSP that creates an HTML table with ...

Get Pure Java Server Pages™ 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.