• 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
Which of the following staments are correct about the following jsp lines:

<jps:useBean id=�name� class=�java.lang.String� />

<%= name %>

1) It won't compile.
2) It is a valid jsp line and it will print the variable called name.
3) It will compile but it will always produce null as the output.
4) It will work if you create a javabean class with only one variable of type java.lang.String.


What do you think the anwer is and why?

Thanks
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

As it exists it won't compile

<jps:useBean id=”name” class=”java.lang.String” />
<%= name %>

-> jps should be jsp

if that was a typo on your part though, then it should compile and run, and I think will always output the value of the name bean, which if no bean exists prior to the <jsp:useBean> tag, then it will be empty (not null)

Mat
 
Troy Peter
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mannu, hi Mat,

I totally agree with Mat reply. So the answer to that mock question would be 2).

This is my understanding of what happens:
This: <jsp:useBean id=�name� class=�java.lang.String� />
translates to:
java.lang.String name = new java.lang.String();

This: <%= name %>
translates to:
out.print(name);

Since name is an empty string, then the output is empty.

Regards,
Troy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic