{"id":32,"date":"2007-08-15T22:03:42","date_gmt":"2007-08-16T02:03:42","guid":{"rendered":"http:\/\/hardlikesoftware.com\/weblog\/2007\/08\/15\/jsp-documents-and-valid-html\/"},"modified":"2007-08-15T22:03:42","modified_gmt":"2007-08-16T02:03:42","slug":"jsp-documents-and-valid-html","status":"publish","type":"post","link":"https:\/\/hardlikesoftware.com\/weblog\/2007\/08\/15\/jsp-documents-and-valid-html\/","title":{"rendered":"JSP Documents and valid HTML"},"content":{"rendered":"<p>I have never been a fan of JavaServer Pages (JSP) but I have used them on a few projects. When JSP Documents (JSPs with XML syntax) were added in version 1.2 I thought if you had to do JSP then JSP Documents were the way to go. I prefer the uniform XML syntax to all the crazy syntax in JSP Pages. <\/p>\n<p>Recently I&#8217;ve been focused on producing valid HTML. Perhaps too focused. A while back I bought into the XHTML is the wave of the future so we should all start using XHTML now hype. Now I see that serving good old HTML 4.01 is the best choice. See <a href=\"http:\/\/www.hixie.ch\/advocacy\/xhtml\">Sending XHTML as text\/html Considered Harmful<\/a> for why. My old habit of using XML style empty elements such as &lt;br \/&gt; was getting me into trouble with HTML validators. The HTML Validator Firefox extension (using Tidy) will flag the slash in red even though it doesn&#8217;t give a written error. The W3C validator gives an error if the \/&gt; results in character data where it isn&#8217;t allowed. This can happen on the empty meta tag. <\/p>\n<p>After reading about <a href=\"http:\/\/www.cs.tut.fi\/~jkorpela\/html\/empty.html\">empty elements<\/a> and what &lt;br \/&gt; really means in HTML I wondered how is it even possible for a JSP Document to generate valid HTML.<\/p>\n<p>Because JSP Documents must be valid XML an empty tag like meta must end with \/&gt; (or &lt;\/meta&gt; which doesn&#8217;t help) and this results in a validation error because character data is not allowed within the head tag.<\/p>\n<p>This really surprised me. I looked and looked for a way to tell the JSP Document to output valid HTML but couldn&#8217;t find one. If you know of a way please tell me. The jsp:output action gives you control over the DOCTYPE and XML declaration. I was expecting it to also let you specify that the output method is HTML just like <a href=\"http:\/\/www.w3.org\/TR\/xslt20\/#element-output\">XSLT does<\/a>. But it doesn&#8217;t.<\/p>\n<p>Unless I&#8217;m missing something obvious JSP Documents should come with a warning &#8211; &#8220;Warning JSP Documents don&#8217;t output valid HTML by default&#8221;. I wonder why the oversight. Did the JSP designers buy into the XHTML hype as well?<\/p>\n<p>There are two ways I know of to work around this issue. One is to use a CDATA section. For example: <\/p>\n<pre>\r\n  &lt;head&gt;\r\n    &lt;![CDATA[&lt;meta http-equiv=\"Content-Type\" content=\"text\/html\"&gt;]]&gt;\r\n    ...\r\n<\/pre>\n<p>The other is to use a tag library such as <a href=\"http:\/\/struts.apache.org\/1.2.7\/userGuide\/struts-html.html\">Struts HTML<\/a> that knows how to output either HTML or XHTML. But this doesn&#8217;t help with the meta tag.<\/p>\n<p>Even with this minor snag I still prefer JSP Documents to JSP pages but that isn&#8217;t saying much.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have never been a fan of JavaServer Pages (JSP) but I have used them on a few projects. When JSP Documents (JSPs with XML&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/hardlikesoftware.com\/weblog\/2007\/08\/15\/jsp-documents-and-valid-html\/\">Continue reading<span class=\"screen-reader-text\">JSP Documents and valid HTML<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,3],"tags":[],"_links":{"self":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts\/32"}],"collection":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":0,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}