File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EduardoCobian Q 29

 
Tracy Woo
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Kyle Tang
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bruce Jin
Ranch Hand
Posts: 672
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tauqueer Ali
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced a very similar question in actual SCWCD exam.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic