Re: Garret Wilson's question: "So how do I output <!DOCTYPE html> for HTML 5 with the JSP document (JSPX) syntax? Is it even possible?"
This can be done with jsp:text
. (It cannot be done with jsp:output
).
The current version of JSP specification is JavaServer Pages Specification Version 2.3. (Implemented in current Java EE 8 (Tomcat 9.x) as well as previous Java EE 7 (Tomcat 8.x)). Quoting from chapter JSP.5.6 "<jsp:output\>":
The doctype-root-element
, doctype-system
and doctype-public
properties allow the page author to specify that a DOCTYPE be automatically generated in the XML prolog of the output. Without these properties, the DOCTYPE would need to be output manually via a <jsp:text>
element before the root element of the JSP document, which is inconvenient.
A DOCTYPE must be automatically output if and only if the doctype-system
element appears in the translation unit as part of a <jsp:output>
action. The doctype-root-element
must appear and must only appear if the doctype-system
property appears, or a translation error must occur. The doctype-public
property is optional, but must not appear unless the doctype-system
property appears, or a translation error must occur.
Until somebody asks the specification committee for more flexibility here, and a new version of specification comes out, this is all that we have.
An example using jsp:text
:
<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.3">
<jsp:directive.page contentType="text/html" />
<jsp:text><!DOCTYPE html></jsp:text>
<html lang="en">
<head>
<meta charset="${pageContext.response.characterEncoding}"/>
<title>Hello world</title>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
</jsp:root>