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 Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean doubt..

 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output will be ""
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic