Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP <jsp:useBean ... /> tag: Difference between 'class' and 'type'

Reply
Thread Tools

JSP <jsp:useBean ... /> tag: Difference between 'class' and 'type'

 
 
Sean Aitken
Guest
Posts: n/a
 
      06-03-2004
Hello,

I'm trying to gain a better understanding of the included tag libraries
with JSP. The <jsp:useBean tag seems farily straightforward, in that it
sets a page variable from an object in any scope, with a variety of options.

I see examples listed that interchange the 'class' and 'type' attribute,
but to me it's not real clear as to their distinction. Can anyone
explain their difference?

One thing I have noticed is that if I don't yet have a variable declared
in the given scope, using the 'type' attribute causes an exception to be
thrown, whereas the 'class' attribute does not. It seems that when I
specify "class", it actually creates a new instance of the specified
variable / bean.

Thanks!!
-Sean
 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      06-03-2004
Sean Aitken wrote:

> Hello,
>
> I'm trying to gain a better understanding of the included tag libraries
> with JSP. The <jsp:useBean tag seems farily straightforward, in that it
> sets a page variable from an object in any scope, with a variety of
> options.
>
> I see examples listed that interchange the 'class' and 'type' attribute,
> but to me it's not real clear as to their distinction. Can anyone
> explain their difference?


The "class" attribute specifies the actual class of the bean instance.
The "type" attribute specifies the Java type by which the instance is
handled, which may be a superclass of the bean's class or an interface
implemented by it.

> One thing I have noticed is that if I don't yet have a variable declared
> in the given scope, using the 'type' attribute causes an exception to be
> thrown, whereas the 'class' attribute does not. It seems that when I
> specify "class", it actually creates a new instance of the specified
> variable / bean.


If there is not already an attribute of the specified id in the
specified scope then useBean attempts to create one. It can only do
that if it knows what class to instantiate. If there _is_ already a
matching attribute then useBean attempts to use it; it will be cast to
the type specified by "type" if that is provided, or to the type
specified by "class" otherwise.

You would benefit from reading the specifications for these behaviors.
The JSP spec is available from Sun as a free download, and it describes
all of this.

--
John Bollinger

 
Reply With Quote
 
 
 
 
Sean Aitken
Guest
Posts: n/a
 
      06-03-2004
Perfect!

That explanation makes sense. I actually spent about 20 minutes reading
through the applicable portions of the JSP spec PDF before making this
post. They seemed dodgy on the issue. Your explanation made perfect
sense. Guess I need to read better next time. :0)

Thanks!
-s-

John C. Bollinger wrote:

> Sean Aitken wrote:
>
>> Hello,
>>
>> I'm trying to gain a better understanding of the included tag
>> libraries with JSP. The <jsp:useBean tag seems farily
>> straightforward, in that it sets a page variable from an object in any

--snip--
 
Reply With Quote
 
Alex Hunsley
Guest
Posts: n/a
 
      10-21-2004
Sean Aitken wrote:
> Perfect!
>
> That explanation makes sense. I actually spent about 20 minutes reading
> through the applicable portions of the JSP spec PDF before making this
> post. They seemed dodgy on the issue. Your explanation made perfect
> sense. Guess I need to read better next time. :0)
>
> Thanks!
> -s-


Hi Sean
Could you plase bottom-post, rather than top posting? It makes threads
much more easy to follow.
More info here:

http://www.cs.tut.fi/~jkorpela/usenet/brox.html

alex
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the essential difference between JSP and JSF? marcwentink@hotmail.com Java 2 02-27-2007 11:34 PM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Difference between jsp:useBean and page import package ??? Ulf Meinhardt Java 1 10-14-2004 07:36 AM
Difference between <jsp:useBean> and <bean:define> ? Anan H. Samiti Java 1 09-27-2004 01:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57