John Pearson

Ranch Hand
+ Follow
since Oct 19, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Pearson

I couldn't see any problem with the code as you listed it, so I wrote a quick test app just to see what it did. It worked just fine! Maybe it is a mistake in the wording of the question.
You can manipulate body content of a SimpleTag. To get at the body contents, you have to use the invoke() method to write it to a Writer, and then use the appropriate methods of that Writer to get the contents.

Since I always find it easier to understand code rather than explanations like I've just given, here's a short example for a SimpleTag that will take the tag's body as a String, convert it to uppercase, and print it out.

Congratulations! And thanks for the notes on your preparation.
Dee's right. A classic tag handler doesn't know anything about SimpleTags. It can only take a Tag for setParent(), and so that what it returns for getParent(), which is what's called by findAncestorWithClass(). To make it possible for a classic tag to have a SimpleTag parent, the SimpleTag gets wrapped by a TagAdapter, which does implement the Tag interface.

If getParent() returns a TagAdapter, you can then call TagAdapter's getAdaptee() method to get the SimpleTag that you really wanted.

So option 2 won't work. If you really want to use findAncestorWithClass(), you can call findAncestorWithClass(this, TagAdapter.class), followed by getAdaptee(). If you have more than one SimpleTag in the hierarchy, you'll of course need to check that the SimpleTag returned by getAdaptee() is, in fact, an instance of the SimpleTag class you're looking for.

By the way, this is way more detail than you need for the exam, but I always liked to know how things really worked.
Spectacular score!!! Congratulations!
14 years ago
In the servlet that is generated from the JSP, the container makes a call to an include() method. One of the parameters is the request path. If you specified a parameter with <jsp:param ... />, that parameter is tacked onto the end of the path.

For instance, if my JSP contains:

the servlet generated by the container (in this case, Tomcat) will have:

Not the most readable code in the world, but it works.

Hope this helps.

Sorry for the multiple edits. Those smilies kept trying to sneak back into my listings.

[ June 16, 2008: Message edited by: John Pearson ]

[ June 16, 2008: Message edited by: John Pearson ]
[ June 16, 2008: Message edited by: John Pearson ]
Since C, D, and E all use nonexistent methods, B has to be the other correct answer. I suppose since getOutputStream returns a ServletOutputStream, and that has methods that include print(String s) and println(String s), it's certainly possible to write text using a stream.

So, while A is clearly the best choice for writing text, B is also correct.
In addition to the previous reply, it's important to note that a JspFragment must not contain scriptlets or scriptlet expressions. For more complete information on JspFragment, check out Sun's Servlet API docs.
How about using request.getParameterNames() first to get an Enumeration of all the parameter names? Then use those names with request.getParameter().
14 years ago
On the first question, 1 and 3 are correct, because <jsp:getProperty> does print out the result. It gets the requested property, converts it to a String, and sends it to the implicit out object, so it will have the same effect as 3.

On the second question, I'd agree that with you that 1 should be a correct answer.
You are right, e is also correct. I ran a quick test just to make sure I wasn't missing anything, and it failed with a "cannot find symbol" compile error.
You are right that it wouldn't make sense to have a Simple tag with <body-content>JSP</body-content>. You'll get an error from most containers if you specify a body-content of JSP in your TLD.

The following is from the JSP 2.0 spec:
Because JSP fragments do not support scriptlets, the <body-content> of a SimpleTag cannot be �JSP�. A TLD is invalid if it specifies �JSP� as the value for <body-content> for a tag whose handler implements the SimpleTag interface. JSP containers are recommended to but not required to produce an error if �JSP� is specified in this case.
Awesome score! Congratulations!