Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why JSPX does not like empty elements?

Tags:

html

xhtml

jsp

jspx

this <div id="adiv"></div> will in JSPX somehow be translated into <div id="adiv" />. The way I got it to work is to add empty comments inside like <div id="adiv"><!-- --></div>. I dont understand why this is happening and is there a better to solve this issue?

like image 246
Bobo Avatar asked Aug 15 '26 14:08

Bobo


1 Answers

That's by JSP specification:

JSP.6.2.3 Semantic Model

...

To clearly explain the processing of whitespace, we follow the structure of the XSLT specification. The first step in processing a JSP document is to identify the nodes of the document. Then, all textual nodes that have only white space are dropped from the document; the only exception are nodes in a jsp:text element, which are kept verbatim. The resulting nodes are interpreted as described in the following sections. Template data is either passed directly to the response or it is mediated through (standard or custom) actions.

In theory, it should not harm if you use a XHTML doctype to present the document in the client side instead of a HTML doctype. However, even the XHTML spec requires some elements to be not self-closing. Another workaround would be using <jsp:text /> instead of a comment.

<div id="adiv"><jsp:text /></div>

JSP(X) is however an old view technology. Its successor, Facelets, does a better job in this.

See also:

  • JSP Document/JSPX: what determines how tabs/space/linebreaks are removed in the output?
  • Why don't self-closing script tags work?
like image 145
BalusC Avatar answered Aug 18 '26 03:08

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!