• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean doubt..

 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is the output of from the below JSP code?
<jsp:useBean id="name" class="java.lang.String" />
<%= name %>


I think answer will be nothing (empty string), because it is equivalent to --
String name = new String();
System.out.println(name);
name is not assigned to any string value, hence its value will be empty string...

Thanks,
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,

if there is no String named 'name' in the context.

Otherwise, that will be the value.

As you know, useBean is popularly used after the object has been created somewhere already; like from a servlet that called the jsp.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is equivalent to --
String name = new String();


It is not equivalent.

It is more like the following pseudocode:

If name exists in the context
return that name instance
else
String name = new String();
end-if
 
Jaime Yong
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output will be ""
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic