Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock question

 
Mannu hak
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the o/p for the following and why??
*********
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>
 
Mannu hak
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please help with this. Thanks.
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Name is Anand(in red color)
My Name is Anand(in green color)

what is your doubt in this?
Please be specific while asking doubts.
 
Mannu hak
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From where did the
(in red color)
(in green color) came from?
 
AmitKumar Jain
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Riz...

Out will be:

My Name is Anand
My Name is Anand

(Riz meant... The first line is printed in Red and the second in green )
 
Radhika Jonnalagadda
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My answer would be:

My name is Anand (in red color)
because, doEndTag() is returning 'SKIP_PAGE' so that the rest of the page doesn't get executed.And hence, "My name is Anand (in green color)" doesn't get printed.Correct me if I am wrong.
Thanx.
 
Kuppusamy Venkatasubramanian
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The answer was

<span style=" color= red;font-size=30">
My Name is Anand</span>

I tested and found this. The reason has been said in the reply by Radhika before this thread..

SAM..
 
Krishna Srinivasan
Ranch Hand
Posts: 1876
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are using SKIP_PAGE, the process will skip the current page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic