This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JSP and the fly likes jsp:useBean tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:useBean tag" Watch "jsp:useBean tag" New topic

jsp:useBean tag

Sudeep Singh

Joined: Jan 27, 2004
Posts: 6
Hi All,
i have a curiousity regarding "jsp:useBean" tag. When we have to import classes for using "jsp:useBean" tag then why don't we make the objects straight away using that class constructor. Is that something to do with scope?Also are these objects created at compile time itself ? Kindly explain to me in detail. Thanks in advance
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
I'm not sure what you asking in your first question. But, since the bean can be in any scope, it can't be set/created at compile time. In fact, the JSP may not even need to ever create the bean being used. It may have been constructed and stored in a context by some Servlet during initialization much earlier.

Sudeep Singh

Joined: Jan 27, 2004
Posts: 6
Hi Nathaneil,
Actually i wanted to know the difference between object of a bean created by normal method i.e.(using new()) and by using jsp:useBean tag.if no difference is there then why do we at all use jsp:useBean tag?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

jsp:useBean does more than create an instance of the class. If it finds a bean with the specified name already in the specified scope, it doesn't create a new instance at all -- it just hooks up the existing bean to the scrpting variable. When an instance is created, it is placed in the specified scope.
This isn't anything you could not do with a scriptlet on the page, but is handier and helps keep Java scriptlets out of the page.

[Asking smart questions] [About Bear] [Books by Bear]
Sudeep Singh

Joined: Jan 27, 2004
Posts: 6
Thanks everyone for your help
I agree. Here's the link:
subject: jsp:useBean tag
It's not a secret anymore!