Which statements are correct regarding the following jsp lines that use a tag library? <%! Vectot vector =new java.util.Vector();%> <% vector.addElement(“one” ; vector.addElement(“two” ; %> <prefix:suffix attr='vector' /> 1) A vector can't be assigned to a tag handler attribute 2) The program will compile and assign the vector's content to the attribute attr. 3) The program will assign the content of vector if assigment is: attr='<%= vector %>' 4) Microsoft is the worst software company in history.
The given answer is 3. But I am unable to understand what is meant by "the content of vector". Can somebody please explain?
attr="vector" means, the string literal "vector" is assigned to that attr. in this case, attr has type String. attr="<%=vector%> means, attr has type Vector, and it is assigned value vector. In this case, I guess you need to explicitly define the type for attr, in the tld file. content of the vector means, the real Vector object, not just the String "vector". Kyle
I feel this question is unclear. <prefix:suffix attr='vector' /> means a string ‘vector’ is assigned to attr. I think this is OK. I think 1) is true: A vector can't be assigned to a tag handler attribute. I hope some one can clear this up since I am not very sure about this. Thanks
BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design
The JSP fragmentwill translate to (among other things) the statementwhere "tag" is a variable referring to the tag object, and "expr" can be any Java expression or variable (including a Java primitive). Of course, if the tag does not have a setAttr() method taking an appropriate argument type, the compiler will complain. Still a bad question because I feel that 3. and 4. are equally correct - Peter