Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem: Sample Question

 
rashmi wadhera
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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)
 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • 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...
 
Bin Gao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is D.
 
Frederic Filiatrault
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • 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 !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic