When a JSP invokes a tag, a new instance of the tag handler class is instantiated, two or more methods are called on the handler, and when the doTag() method completes, the handler object goes away. (In other words, these handler objects are not reused.)
BE the Container
Look at each of the TLD/JSP pairs. Assume that the tag handler prints the body of the tag. Then answer the following questions about each one... what’s the result? If it works, what prints out? Which methods in the custom tag class are invoked?
<tag> <description></description> <name>simple</name> <tag-class>foo.SimpleTagTest</tag-class> <body-content>empty</body-content> </tag>
Simple Tag: <myTags:simple> This is the body of the tag </myTags:simple>
What do you see in the browser?
If it works, which SimpleTag lifecycle methods are called in the handler?
<tag> <description></description> <name>simple</name> <tag-class>foo.SimpleTagTest</tag-class> <body-content>scriptless</body-content> </tag>
Simple Tag: <myTags:simple> ${2*3} </myTags:simple>
What do you see in the browser?
If it works, which SimpleTag lifecycle methods are called in the handler?
BE the Container Answers
<tag> <description></description> <name>simple</name> <tag-class>foo.SimpleTagTest</tag-class> <body-content>empty</body-content> </tag>
Simple Tag: <myTags:simple> This is the body of the tag </myTags:simple>
What do you see in the browser?
It doesn’t work because it is supposed to have an empty body. |
org.apache.jasper.JasperException: /simpleTag1.jsp(1,76) According to TLD, tag myTags:simple must be empty, but is not |
If it works, which SimpleTag lifecycle methods are called in the handler?
<tag> <description></description> <name>simple</name> <tag-class>foo.SimpleTagTest</tag-class> <body-content>scriptless</body-content> </tag>
Simple Tag: <myTags:simple> ${2*3} </myTags:simple>
What do you see in the browser?
Simple Tag: 6 |
If it works, which SimpleTag lifecycle methods are called in the handler?