• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in <jsp:usebean..

 
geeta vemula
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is from http://www.javaranch.com/carl/SCWCD.htm#Answer%2010)

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.

Answer is 2.

What it will print exactly? Is it printing value of some name variable declared as <%! String name="abc"; %> If yes then what if variable name in not declared?

Thanks,
Geeta
 
Andriy Pererva
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Geeta!
First of all you should correct a little mistake in your code, I mean jsp:useBean instead of jps.
Let's resolve this question in such logical sequence:
1) Because of 'class' attribute the object will be actually instantinated (if it is not exist)
2) Instantination of JavaBean is always deals with no-arg constructor
3) Open J2SE API, and looking for this constructor
4) Specification clearly says, that "Initializes a newly created String object so that it represents an empty character sequence"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic