tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Tomcat 8 jspx and HTML5
Date Sat, 08 Aug 2015 12:32:06 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Kevin,

On 8/7/15 10:24 AM, Kevin Hale Boyes wrote:
> 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>

This is a common problem, and the reason for it is that <script> for
some reason, in every browser I've ever seen, completely fails to
parse correctly if it's a self-terminating tag like <script />. When
you use .jspx, the input and output are assumed to be both well-formed
XML where <script /> is perfectly acceptable.

IMO this is a problem with browsers. Even in standards-compliance
mode, they seem to demand that <script> be a paired tag. Thus, all of
our script tags that reference external files are written like this:

  <script src="(script)" type="text/javascript"><!-- --></script>

This will force the XML serializer to retain the comment and force a
paired tag.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJVxfbGAAoJEBzwKT+lPKRY6UkP/1+8LqTSN9JKPDh1u63Bsqk1
ujizF8YlQ/m4alNPVp/BzMPh4o9azeO+5M6afSTRO0jGAtMUiXtfNEjIyY05gG+Z
FdoLFVnC2bvWAf4uFwkxQCPsvXnMGVLBF77NDUOL0mrR5bEaBIWhj+cpD3gjfWRh
rLCo5UtLNpVnPCq+ZRJnwXOhfA82DpSpklZpupsQYJfqJWat8R3R8S0zSduWODUN
TVYnW/861Be3UEo+eTKHZ94Jt9GFsTOyieCV+HvmmZFy6Vm2TBtF0891jfqh3DtF
Y/D1L/+66pLgmro+pCYaUfjFQH06rYQge5Wlww8Mr1m3rAOyVdBwyiwV5tEr8BlC
s+l1e2B1ZmBWPS8czBg0hNoEC3rO6sSYnMzLpIRiiVUTauWrLoxn6FoGVuKkgTR9
zpjJ1IjaBTLDAw6B6JGx4Y4QPcQf7Q5QvLve4T7A8cZtvQ3tPVHg3GmyzHl+b+c1
YIYIyMK7RVjaPsjVqAg6BAgUlyqcbeorT+h6uKJt2k/a8Tdl1/bSJ8Q6sBHy36rs
sYj5knTHOU3G5rPs3ha7P+6a4emF+8MsmZ7ZiwQ01ahwY4VIqwfWcTDzRNOCS6Jw
PNKILrYdqNgU4rXwj8BoI9p/R+zzFs7KAdwiEiHT/HZerm5IQJNSyzfJG5OllUHB
G0ugoHUV1/zkbwSIgdfp
=4mQ3
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message