I want to use a jspx to generate some HTML5 but I'm running into a strange problem. I've produced a very small test to demonstrate the problem.
In the jspx pasted below if I remove the comment in the <script> tag (in the head) then the page won't render properly in chrome browser. When I have a non-empty <script> tag then it renders fine. I've used curl to look at the HTML being generated from Tomcat and can see the difference. When the <script> tag is empty it gets rendered as a self-closing tag: <script src="sayhi.js" type="text/javascript"/> When I put in the comment it gets rendered as I expect (not self-closing): <script src="sayhi.js" type="text/javascript">// tag can not be empty</script> Why does this happen? It's quite natural to write the empty <script> tag and countless example exist so why can't I do it from my jspx? Thanks, Kevin. P.S. the sayhi.js file contains function sayhi() { alert('HI!'); } <?xml version="1.0" encoding="UTF-8"?> <jsp:root version="2.1" xmlns:jsp="http://java.sun.com/JSP/Page"> <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> <head> <script type="text/javascript" src="sayhi.js">// tag can not be empty</script> </head> <body> <h1>HTML5 from jspx</h1> <script type="text/javascript">sayhi();</script> </body> </html> </jsp:root>