Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Another Problem

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic