[ Team LiB ] Previous Section Next Section

Q&A

Q1:

Why do I see my custom tag in the HTML output?

A1:

You most likely forgot to put the taglib directive at the top of the page. You also might not have remembered to use the prefix you defined in the taglib directive, or you mistyped the prefix or the tag name.

Q2:

Why do I get a compile error when I use a custom tag?

A2:

Well, the first thing to check is that it's really the tag that's causing the problem. Try removing the tag and see whether that clears up the problem. Next, make sure that you have installed the tag library on the Web server. The class files should be under the WEB-INF/classes directory. (WEB-INF must be capitalized, so don't count on web-inf working the same way.) Also make sure you have a TLD file and that the web.xml file in the WEB-INF directory has the correct pathname for the TLD.

Q3:

Why do I get a runtime error when I try to set an attribute value?

A3:

There is probably some mismatch between the attribute type in the custom tag and the attribute value you are trying to set. For instance, trying to store the string "Fred" into an integer value isn't going to work.

Q4:

I created get and set methods, so why doesn't the JSP engine recognize my attributes?

A4:

Don't forget that you must also define the names of the attributes in the TLD file.

Q5:

When I use a body tag, why does the JSP engine stop responding?

A5:

You are probably stuck in an infinite loop caused by your doAfterBody method returning EVAL_BODY_AGAIN, instead of SKIP_BODY, over and over.

Q6:

I tried to write out some code in <% %> and reevaluated the body text. Why do the <% %> tags show up in the output?

A6:

Remember, the JSP engine parses the body text only one time. It might evaluate custom tags in the body text multiple times, but after the text is parsed, that's it.

Q7:

I rewrote the body text and returned EVAL_BODY_AGAIN. Why do I still see the original body text?

A7:

Again, the JSP engine parses the body text only once. You will always receive the original body text in doAfterBody.

Q8:

I put a value in the page context, so why doesn't the JSP have a variable to hold the value?

A8:

You might have forgotten to create the TagExtraInfo object, or you forgot to link the TagExtraInfo object to the tag class by adding a <teiclass> item in the TLD file.


    [ Team LiB ] Previous Section Next Section