Examples / Server Examples / JSP Header

JSP Header

example java server jsp

This example uses JSP to show a header on every page.

It starts with a header.html file that contains the header:

<div style="border: thin solid black; padding:5px;">
  <a href="index.jsp">Home</a>
  <a href="about.jsp">About</a>
  <a href="pictures.jsp">Pictures</a>
</div>

Then it contains a few JSP files that each include the header:

index.jsp

<!DOCTYPE html>
<html>
  <head>
    <title>Home</title>
  </head>
  <body>
    <%@ include file = "header.html" %>
    <p>Welcome to my homepage!</p>
  </body>
</html>

about.jsp

<!DOCTYPE html>
<html>
  <head>
    <title>About</title>
  </head>
  <body>
    <%@ include file = "header.html" %>
    <p>About me: I'm an example!</p>
  </body>
</html>

pictures.jsp

<!DOCTYPE html>
<html>
  <head>
    <title>Pictures</title>
  </head>
  <body>
    <%@ include file = "header.html" %>
    <p>This page will contain pictures I've taken.</p>
  </body>
</html>

webpage with header



Comments and Questions

Happy Coding is a community of folks just like you learning about coding.
Do you have a comment or question? Post it here!