I have been trying to figure out why the following situation is arising in <body-content>empty</body-content>. If I provide the entry in tld then specifying a content in the body of the tag should give an exception, but it's working smoothly in my case. Please see the following snippets:
<mine:advice>
Content should not print...
</mine:advice>
When I debug the tag handler, getJspBody() does not return null. I am using Tomcat 6.0. Is it container specific property? Please help, this trivial issue has taken my lot of time.
Sorry for the mistake. My container is ignoring all the body-content settings and taking 'scriptless' as the value. I know for tomcat the default is 'JSP' for tags, but I'm not sure why this behavior is occurring. Thanks for your reply. I will update with my findings.
I can't answer about error in your container but as far as I know JSP is not the default for any of the tags
and in simple tags JSP are not allowed in body as the body content of JSPFragment does not support scriptlets.
check this faq link .
webpage
I'm getting this problem as well and its driving me nuts. Either I completely misunderstand what a body-content of empty is meant to do, or there is a bug in my container implementation (Tomcat 6.0.18 on Linux).
I am expecting to see an error message when the second tag is encountered in the JSPX since the tag supplies a body, yet the TLD says "empty" for body-content. However my container is writing out the tag body regardless.
Here are the relevant files if someone would care to verify for me - maybe there is a really obvious mistake I've made below???
Yes,same result in Tomcat 5.5.9 too.Output of your code is
About to call TestBodyContentEmptyBug...Done calling TestBodyContentEmptyBug...
--------------------------------------------------------------------------------
About to call TestBodyContentEmptyBug with a body...
Hello from the body of TestBodyContentEmptyBug... this body should cause an error... should it not?
Done calling TestBodyContentEmptyBug...
--------------------------------------------------------------------------------
But i remembertesting similar program in case of simple tags on tomcat 6.0.18.And exception was raised there (i think) when tld declared the body content to be empty and i passed body in the invocation of tag.
Did you test for simple tags too?
Thanks for the replies so far - I've got a little further with this problem now.
It seems that it only happens with JSP Documents and not with JSP Pages.
So when I convert my TestBodyContentEmptyBug.jspx JSP Document to TestBodyContentEmptyBug.jspJSP Page , the container successfully throws the expected error:
Filename TestBodyContentEmptyBug.jsp
The error message seen in the browser:
So - can anyone tell me why this is? Why would a JSP Document behave differently than a JSP Page with regard to body-content?
I see you've filed this as a bug in Tomcat: body-content of empty in TLD ignored for JSP Documents. That's probably the best move. I imagine this is an oversight in the JSP document translator, since the container can't enforce the "empty" content by XML schemas but instead has to do it programmatically at translation time, and I guess that test is missing in the translation engine. You could also try this on non-Tomcat containers (e.g. Caucho Resin) and see what behaviour that gives.