logo

MMBase tips

HTML5 jspx template

tip #16 / Tue 20 Jul 2010 / André / 0 comments

A jspx is normally used to produce xhtml. It is possible though to write valid HTML5 documents.

After some Googling I found that to have a jspx to output valid HTML5 you'll need these jspx headers and page directives.

<jsp:root 
    xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns="http://www.w3.org/1999/xhtml"
    version="2.0">
   
  <jsp:directive.page contentType="text/html" pageEncoding="UTF-8" />
  <jsp:output omit-xml-declaration="true" />
  <jsp:output doctype-root-element="HTML"
              doctype-system="about:legacy-compat" />

It generates html with a proper DOCTYPE for HTML5.

<!DOCTYPE HTML SYSTEM "about:legacy-compat">

The parts 'SYSTEM' and 'about:legacy-compat' are not really needed but come with the trade. When writing the HTML5 specifications the working group kept in mind that some html generators needed such a DOCTYPE legacy string.

Template

A bare jspx template would look like this.

<jsp:root 
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">

<jsp:directive.page contentType="text/html" pageEncoding="UTF-8" />
<jsp:output omit-xml-declaration="true" />
<jsp:output doctype-root-element="HTML"
doctype-system="about:legacy-compat" />

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>HTML5</title>
</head>
<body>
<h1>HTML5</h1>
</body>
</html>

</jsp:root>

MMBase HTML5 template

And a template to use with mmbase taglib.

<mm:content
expires="120"
type="text/html"
encoding="UTF-8"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:mm="http://www.mmbase.org/mmbase-taglib-2.0"
postprocessor="none">
<jsp:output omit-xml-declaration="true" />
<jsp:output doctype-root-element="HTML"
doctype-system="about:legacy-compat" />

<mm:cloud>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>HTML5</title>
</head>
<body>
<h1>HTML5</h1>
</body>
</mm:cloud>
</mm:content>

It results in a page with a 120 seconds expire header.

0 comments

RSS feed

Tweet this article

Most mentioned links:

MMBase documentation
MMBase API
MMBase SVN
Bugtracker
MMBase Taglib reference
The reference for all tags mm