The Java EE 6 Tutorial

Adding HTML Head and Body Tags

The HTML head (h:head) and body (h:body) tags add HTML page structure to JavaServer Faces web pages.

The following is an example of an XHTML page using the usual head and body markup tags:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Add a title</title>
  </head>
  <body>
    Add Content
  </body>

The following is an example of an XHTML page using h:head and h:body tags:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html">
  <h:head>
    Add a title 
  </h:head>
  <h:body>
    Add Content
  </h:body>

Both of the preceding example code segments render the same HTML elements. The head and body tags are useful mainly for resource relocation. For more information on resource relocation, see Resource Relocation Using h:output Tags.