This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes usebean without class attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "usebean without class attribute" Watch "usebean without class attribute" New topic
Author

usebean without class attribute

himani jangid
Greenhorn

Joined: Jul 04, 2013
Posts: 18
i have a confusion in using usebean tag without class attribute,
as the example given in head first servlets <jsp:useBean id="person" type="foo.Person" scope="Page"/>

n it says that if the person bean must already exists then only it will work.

1. so my question is this that is it possibility that we can make this work because if we bean is already declared in page scope(then it must be declared in the same page ), n then if we use this line in same page it will give an exception of having duplicate bean.

2. n if we declare it in request scope then also in using it on different jsp page it gives exception "java.lang.InstantiationException:bean not found in the scope"

3. but if i declare it in session scope then it is working fine on the next jsp page.

so please solve my above mentioned questions
himani jangid
Greenhorn

Joined: Jul 04, 2013
Posts: 18
sorry, i got the answer of 2 and 3... i was doing some silly mistake but still not sure about question 1
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Basically when you use the type attribute, and not the class attribute, it can never create the instance for you. The instance must exist at the time of evaluating the jsp:useBean tag.
The only way to make <jsp:useBean id="person" type="foo.Person" scope="Page"/> work is to have scriptlet code on the same page setting that value into the pageContext attribute before the jsp:useBean statement is executed.






Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Or to have properly created the scoped variable in the page controller servlet. But in that case, the useBean is needless and useless if the page uses JSTL and EL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: usebean without class attribute
 
Similar Threads
doubts in HFJS
Whats the error???
jsp:useBean
jsp:useBean tag Rules
use of type in <jsp:usebean>