• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem: Sample Question

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pls provide solution to this problem:



The contents of taghandler class are

package tags;

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

import java.io.*;

public class myhead extends TagSupport

{

private String color;

private String fontSize=""20"";



public void setColor(String b)

{

color=b;

}



public void setFontSize(String f)

{

fontSize=f;

}



public int doStartTag()

{

try

{

JspWriter out=pageContext.getOut();

out.println(""<span style=\"" color= ""+color+"";font-size=""+fontSize+""\"">"");

}

catch(IOException e)

{

System.out.println(e);

}

return(EVAL_BODY_INCLUDE);

}



public int doEndTag()

{

try

{

JspWriter out=pageContext.getOut();

out.println(""</span>"");

}

catch(IOException f)

{

System.out.println(f);

}

return (SKIP_PAGE);

}

}





The contents of tag library descriptor heads-taglib.tld are

(I have just omitted the important statements like tlibversion ,jspversion etc to save space)

<tag>

<name>heading</name>

<tagclass>tags.myhead</tagclass>

<bodycontent>JSP</bodycontent>



<attribute>

<name>color</name>

<required>false</required>

</attribute>



<attribute>

<name>fontSize</name>

<required>false</required>

</attribute>



</tag>

</taglib>





the contents of jsp file are

<HTML>

<HEAD>

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

</head>

<he:heading color=""red"" fontSize=""30"">My Name is Anand</he:heading>

<he:heading color=""green"" fontSize=""40"">My Name is Anand </he:heading>

</html>



The output generated is


A My Name is Anand (red color)

My Name is Anand (green color)

B My Name is Anand(green color)

My Name is Anand(red color)

C My Name is Anand(green color)
D My Name is Anand(red color)
 
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,

What is wrong ? Two things seem wrong for me :
1) doEndStart() should return EVAL_PAGE (why do you return SKIP_PAGE?)
2) Your JSP files is incomplete since your output got "A My name is ..."...

Please elaborate so I can help you out...
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is D.
 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok ! Sorry, I didn't understand that the output was the answers list.

Same thing here. your DoEndTag returns SKIP_PAGE, so it stops there, after the first evaluation of your 2 custom tags in the JSP.

Should have returned EVAL_PAGE to have the other custom tag evaluated.

Try to find the traps. Almost all the questions are trapped like that.
Try to find weird thing like SKIP_PAGE. It isn't normal so the example won't work as logically it supposed (in this case, evaluating the two tags).

Hope this will help you !
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic