JSP include HTML body overrides HTML BODY tag that is included? -
JSP include HTML body overrides HTML BODY tag that is included? -
i'm facing confusion how jsp include tag works. what's happening base of operations page's body tag has id attribute of included jsp.
base.jsp
<%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>jsp page</title> </head> /* base of operations jsp has no id body */ <body> <h1>hello world!</h1> <jsp:include page="include.jsp" /> </body> </html>
include.jsp
<%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>jsp page</title> </head> /* here included jsp has body id specified */ <body id="includebody"> <h1>hello include!</h1> </body> </html>
when go base.jsp page, firebug finds 1 body tag ok indicates html body tag has id attribute of "includebody"
outcome:
<html> <head> <meta content="text/html; charset=utf-8" http-equiv="content-type"> <title>jsp page</title> </head> /* why body has id ??? */ <body id="includebody"> <h1>hello world!</h1> <meta content="text/html; charset=utf-8" http-equiv="content-type"> <title>jsp page</title> <h1>hello include!</h1> </body> </html>
the base.jsp has body without id specified , include.jsp has body id. looks if don't specify id in body of base.jsp, included jsp body id applied. bug? or should remove body included.jsp (no can true). or add together id base.jsp body won't replaced included body.
it's not bug. it's required behaviour of html5 parsers. happens if parser encounters sec body start tag, looks @ each attribute of sec body start tag , if body element (created first body start tag) doesn't have attribute same name, attribute gets added body element.
the same thing happens if parser encounters farther body start tags, accumulating attributes each onto body element, first instance particular attribute taking precedence.
so, illustration if have
<body id="realbody"> <h1>hello include!</h1> <body id="invalidsecondbody" class="error"></body> <body id="invalidthirdbody" class="erroragain" style="color:red"></body> </body>
then, in dom, body element have id="realbody" , class="error" , style="color:red".
the rule in html5 specified here: http://dev.w3.org/html5/spec/tree-construction.html#parsing-main-inbody , search downwards a start tag tag name "body"
, it's lastly paragraph in block.
... [i] add together id base.jsp body won't replaced included body
according above rules, happen, yes. however, shouldn't including 1 entire html document in in first place. accumulated markup horribly invalid , @ mercy of kinds of unusual parser rules 1 above.
html jsp include
Comments
Post a Comment