Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

q on jsp:useBean

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whic of the following useBean actions allow u to locate an instance of the bean called "myBean"with id ="thebean" in session scope, without creating a new instance, if one is not existent already?

<jsp:useBean id="thebean" type="MyBean" scope="session">
<jsp:useBean id="thebean" class="MyBean" scope="session">
<jsp:useBean id="thebean" beanName="myBean" type="MyBean" scope="session">
<jsp:useBean id="thebean" type="MyBean" create="false" scope="session">

I guess it is the first one. Am i right? Otherwise, the first line will throw a compile time error.
 
Priya Jothi
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 1 is correct.But i dont think it'll throw compile time error if the bean doesn't exist already..it'll throw null pointer if you attempt to use such bean in ur code.Correct me guys if am wrong.

Regards,
Priya.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 1 is correct.

If the bean doesn't exist it throws a java.lang.InstantiationException
 
M Rama
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you guys explain why 1 is correct? also, this question means that there has been a session.setAttribute("myBean", xxx) where xxx is a MyBean object. the object xxx needs to be referenced by thebean using the useBean in the JSP and not create a new instance if already not existing. is this right???

btw JayaSiji Gopal where are you getting your questions from? seems like the wordings are confusing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic