tags:

views:

104

answers:

2

I'm really not sure about this: does using "JSP Document" / "JSP in XML notation" imply outputting XHTML?

If so, is there anything special to look after as to produce a "valid" XHTML page?

More specifically: can I have a valid "JSP Document" (JSP in XML) that is producing an invalid XHTML page?

+1  A: 

It depends on your definition of XHTML. For most people, XHTML simply means HTML in well-formed XML. In that sense, JSP Document implies XHTML because JSP Document itself is well-formed XML.

However, JSP Document itself doesn't enforce any XHTML rules. For example, you can still generate XHTML 1.0 Strict document with deprecated tags like <center>.

It's also possible to use custom tags in JSP Document that generates non-XML tags, which renders whole document non-XML.

ZZ Coder
@ZZ Coder: +1, interesting. What would you recommend to serve when using JSP Document? transitional? strict? HTML5 XML? HTML5 HTML? (HTML5 allows closing tags like <br/>)
NoozNooz42
This depends on your audience. I am not involved in the decision but all our pages use transitional. HTML5 doesn't have enough penetration for our targeted market at this moment.
ZZ Coder
+1  A: 

I'm really not sure about this: does using "JSP Document" / "JSP in XML notation" imply outputting XHTML?

It at least implies consuming and producing well formed XML. If you write invalid XML, then it will error during parsing. If it produces well formed XML, then it can impossibly be HTML4 because closing shorttags like br, hr, meta and link is disallowed.

What would you recommend to serve when using JSP Document? transitional? strict? HTML5 XML? HTML5 HTML? (HTML5 allows closing tags like <br/>)

Since it's well formed XML, you should choose either XHTML or HTML5. While HTML5 specification is still in draft mode, it allows closing shorttags. Also see the end of chapter 3.2.2 Elements:

Some elements, however, are forbidden from containing any content at all. These are known as void elements. In HTML, the above syntax cannot be used for void elements. For such elements, the end tag must be omitted because the element is automatically closed by the parser. Such elements include, among others, br, hr, link and meta

HTML Example:

<link type="text/css" rel="stylesheet" href="style.css">

In XHTML, the XML syntactic requirements dictate that this must be made explicit using either an explicit end tag, as above, or the empty element syntax. This is achieved by inserting a slash at the end of the start tag immediately before the right angle bracket.

Example:

<link type="text/css" href="style.css"/>

Authors may optionally choose to use this same syntax for void elements in the HTML syntax as well. Some authors also choose to include whitespace before the slash, however this is not necessary. (Using whitespace in that fashion is a convention inherited from the compatibility guidelines in XHTML 1.0, Appendix C.)


Then, the choice between transitional and strict depends on the degree of web standards you'd like to support. For that, the table at the bottom of this website gives an excellent overview.

To start, you'd like to avoid the Quirks Mode as much as possible since that triggers the box model bug in MSIE browser which causes inconsitenties in margins, paddings, dimensions of the elements when specified by CSS. The lack of the doctype or an incorrect doctype will trigger this mode.

I strongly recommend to pick a Strict doctype since the box model and behaviour would then be as much as possible consistent among the different webbrowsers the world is aware of. Either of the following doctypes is okay, depending on what elements/attributes you'd like to support/vaildate.

XHTML 1.0 strict:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

or the newer XHTML 1.1 (strict, module-based):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;

or the (still in draft mode) HTML5 doctype:

<!DOCTYPE html>

Note that you need to ensure that the HTTP Content-Type header is set to text/html, not application/xml nor application/xhtml+xml when going for XHTML, else MSIE may still go mad since it doesn't support that. Also see the aforementioned doctype website for more detail. The same article indeed mentions that serving XHTML as text/html is considered harmful, but that only applies when it get rendered with the <?xml?> declaration and/or contains inline JavaScripts not embedded in CDATA blocks.

BalusC
@BalusC: great links but in the http://hsivonen.iki.fi/doctype/ that you gave, the author specifically writes that *"serving XHTML as text/html is considered harmful"*. This is wild. Who to trust here? BalusC or the link that BalusC gave? :)
NoozNooz42
It's harmful when it returns `<?xml?>` declaration and/or uses inline Javascripts, but that's both in turn also considered poor practice. I am not sure about JSPX, but Facelets (less or more its successor) doesn't emit the `<?xml?>` declaration after parsing the template. However, the advice to use HTML5 doctype is sound. I didn't realize that closing shorttags is allowed in HTML5 as well.
BalusC
@BalusC: yup HTML5 seems great from that standpoint... Darn, after reading several docs (that's where I learnt about closing the shorttags in HTML5), asking questions here, reading more docs and links you pointed to... I feel that I know both more than before and yet that I'm still somehow confused. This is all a bit messy :)
NoozNooz42
I improved my answer to take HTML5 into account. I myself by the way use HTML5 for "plain" JSP/Servlet and XHTML 1.1 for Facelets. I will however consider to experiment with HTML5 on Facelets.
BalusC