File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes dostartTag return value doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "dostartTag return value doubt" Watch "dostartTag return value doubt" New topic

dostartTag return value doubt

Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
Niko's question

Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)

public class Classic extends TagSupport {
public int doStartTag() {
return SKIP_PAGE;

<%@ taglib uri="correct" prefix="yes" %>
<yes:classic>My Body</yes:classic>

1. (Before)(After)
2. (Before)
3. (Before)My Body(After)
4. (Before)My Body

Answer: 3

I tested it and its working fine! yes the answer comes out as 3 only but why? What i have read as valid return types for doStartTag are SKIP_BODY and EVAL_BODY_INCLUDE but its working correctly here. Can anyone explain why?

Parth Tiwari
| Pursuing Bachelor of Engineering | OSUM Club Leader | SCJP 6 | SCWCD 5 |...
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 2099

Hi Parth,

These are really trick questions that you won't come across on the real exam, don't worry about them too much.

First of all: it compiles because SKIP_PAGE is defined as a public static final int, the compiler doesn't know whether that value applies in this method
Secondly: it runs because the generated Servlet checks only on whether the body should be skipped: see part of the generated code (on tomcat):

The JSP2.0 spec doesn't say anything about what should be done if there is a wrong return code thrown from one the tag-methods, so I find the outcome of this question questionable.


Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163 this worked because it was like this on tomcat 5

ok thanks
It is sorta covered in the JavaRanch Style Guide.
subject: dostartTag return value doubt
jQuery in Action, 3rd edition