aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem: Sample Question 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 "Problem: Sample Question" Watch "Problem: Sample Question" New topic
Author

Problem: Sample Question

rashmi wadhera
Ranch Hand

Joined: Apr 06, 2004
Posts: 44
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)


SCJP1.4, SCWCD1.4 (preparing)
Frederic Filiatrault
Ranch Hand

Joined: Jul 12, 2004
Posts: 69
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...


F.<br />SCJP, SCJD, SCWCD, SCBCD<br /> <br />Failure is not an option... It comes with the software bundle.
Bin Gao
Greenhorn

Joined: Jul 23, 2004
Posts: 12
The answer is D.
Frederic Filiatrault
Ranch Hand

Joined: Jul 12, 2004
Posts: 69
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 !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem: Sample Question