Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another Problem

 
rashmi wadhera
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What wud be the solution to this problem. anyone share the mothod of solving this.

Select any one

The contents of tag handler class MyPage. are

package tags;

import javax.servlet.http.*;

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

import java.io.*;



public class MyPage extends BodyTagSupport {

int k=10;

public int doStartTag() throws JspException {

return EVAL_BODY_INCLUDE;

}

public int doAfterBody() throws JspException {

if(k<13) {

k++;

return EVAL_BODY_TAG;

}

return SKIP_BODY;

}

public int doEndTag() throws JspException {

return EVAL_PAGE;

}

}





the contents of tag library descriptor mypage.tld are :

<tag>

<name>mypage</name>

<tagclass>tags.MyPage</tagclass>

<bodycontent>JSP</bodycontent>

</tag>

</taglib>





the contents of jsp file are

<HTML>

<HEAD>

<%@ taglib uri="page.tld" prefix="he"%>

</head>

<he:mypage>

<%="Hello "%>

</he:mypage>

</html>



On executing jsp file guess Hello would be printed how many times

A Not even Once
B Once
C Twice
D Four
 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again !

I know what was your problem. You think 3 and it is not in the solution.

What a luck for you ! That means there's a trap.

Answer : 4 times.

It is doAFTERbody, not doSTARTbody.

Condition is evaluated after printed.
So, 10, 11, 12 are good but even 13 since AFTER it will not return to evaluate the body again.

Hope this help !
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic