I don't think you can do it .... I recall reading ... in the K&B book (I think) that you can only use scripting in classic tags ... so you can use any scripting in tag files or tags that extend SimpleTag ...
This is a great question and I'm gonna search for the exact page in the K&B book.
SCJP 5.0 (preparing for SCWCD)
Joined: Sep 19, 2008
It is getting confused as the results are varying depending upon the browser we used.
See the generated HTML code they are there as template text but browser simply ignore them.
In fact, Tag File bodies are never allowed to have scripting,
so it’s not an option. But you can declare body-content (using
the tag directive with a body-content attribute) if you want one
of the other two options, empty or tagdependent.
The reason it shows up in the browser is that 'tagdependent' means that the container wont evaluate the body but just pass it thru to your tag (or tag file). EL, other tags and scriptlets are ignored when you use 'tagdependent'.
Found it! And it was right here on JavaRanch! Check out this post ... it explains ... why you can use scriting in classic tags (using 'JSP' in <body-content> in the TLD ) and why SimpleTags cannot (they return JspFragment which does not support scripting)
I've just noticed Im asking an answering my own questions!
Joined: Sep 19, 2008
Thank you sooo much...
But still a minor doubt.
I know tag file and Simple tag body content should be empty or scriptless or tagdependent and should not be jsp.
But my question is if the bodycontent is tagdependent can they have scriptlet in their body?
So they should be displayed as template text...but since JspFragement can not contain scriptlet and has to throw translation error as per the link you posted..
if there were translation error then it would have thrown 500 internal server error right? but it is there in the html but its just the browser that did not display some of the tag....see my edited post for different behaviour of the browser for the same generated html...
So if mozilla can display the expression then that means scriptlet are passed throught the body without container evaluating it........
hmm .. I'm not sure but here's what I think is going ...
the browser (any of them) doesnt understang scriptlets or EL so its just text to the broswer. the container is not evaluating the EL expressions in the body of your tag (or any scriptlets) and is just sending them through as plain text.
The translation error would occur .. I think ... if you used 'JSP' as the value of <body-content> in the TLD of a custom tag that implemented the 'SimpleTag' interface. When the container was trying to load the taghandler, the container would know that JSP is an invalid value for the body content of a 'SimpleTag'.