• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question ID :997810765481

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question ID :997810765481
You want to use a bean that is stored in com/enthu/GUI.ser file. Which of following correctly defines the tag to access it?
The answer given is "<jsp:useBean id="pref" beanName="com/enthu/GUI" />" I think it is wrong because there is no type specified. Am I right?
 
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Win,
Iam afraid you are wrong!.whenever the JSP container finds a jsp:usebean tag it tries to locate,if not found then it instantiates an object of the bean implementation class.It tries to first find the beanName attribute, which if it is there it gives to the java.bean.Instantiate() method.If there is no beanName it looks for the class attribute.Either the beanName or the class should be present for the bean instantiation.If both of them are not there then the bean is already instantiated.Type is an optional attribute which signifies that if the class or beanName is there then it should be able to cast to the type mentioned as per normal java runtime casting rules.
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Win
I think the given syntax is right
as per spec :


...The name of a Bean, as expected by the instantiate() method of the java.beans.Beans class...


The beanName follows the standard bean spec and can be of the form "a.b.c" where "a.b.c" is either class , or the name of serialized resource

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think the answer is incorrect.Because JSP spec 1.2 says:
"At least one of type and class must be present".There is not
class or type being presented in jsp:useBean action.So it is not correct.The jsp:useBean syntax qupted from Spec 1.2:
<jsp:useBean id="name" scope="page|request|session|application" typeSpec />
typeSpec ::= class=���className��� |
class=���className��� type=���typeName��� |
type=���typeName��� class=���className��� |
beanName=���beanName��� type=���typeName��� |
type=���typeName��� beanName=���beanName��� |
type=���typeName���
ruijin yang
 
Rishi Singh
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ruijin
This is from the JSP1.2 specs and it clearly mentions that type is used when we have to give a local name to a object defined in some other jsp.....
"The jsp:useBean action is quite flexible; its exact semantics depends on the
attributes given. The basic semantic tries to find an existing object using id and
scope . If the object is not found it will attempt to create the object using the other
attributes.
It is also possible to use this action to give a local name to an object defined
elsewhere, as in another JSP page or in a Servlet. This can be done by using the
type attribute and not providing class or beanName attributes.
At least one of type and class must be present, and it is not valid to provide
both class and beanName .If and class are present, class must be assignable
to type (in the Java platform sense). For it not to be assignable is a translation-time
error.
The attribute beanName specifies the name of a Bean, as specified in the
JavaBeans specification. It is used as an argument to the instantiate()method
in the java.beans.Beans class . "
Based on this I think the answer is right
 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rishi,
Two days ago,I tryed an example with jsp:useBean action which only has beanName:<jsp:useBean id="customer" beanName="myJSP.Customer" scope="request"> and I got an exception.So I think only beanName is not enough!
ruijin yang
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe there must be "type" if "beanName" exists. I am going to take exam this Friday. I do not have much time to run some example. I appreciate if someone can make this clear.Thanks
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran the example on resin-server
and it is giving error
so i guess Ruijin and Win are right
There have to have 'type' if 'beanName' is there
'beanName' alone wont do
------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Win
BTW , from where are your prep for Design-patterns ?
thankxx
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gagan Indus:
Win
BTW , from where are your prep for Design-patterns ?
thankxx


Hi Gagan:
I just look at the Ken's note and I will check the sun's web site about the Design-patterns. I think it is enough.
 
Enthuware Software Support
Posts: 4803
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question and the given answer are correct. It will initialize the bean using com/enthu/GUI.ser file. You are getting exception because you do not have an appropriate .ser file.
HTH,
Paul.

------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Anil:
The question and the given answer are correct. It will initialize the bean using com/enthu/GUI.ser file. You are getting exception because you do not have an appropriate .ser file.
HTH,
Paul.


Hi paul:
I am not sure how you did the test. But from the JSP spec, you can see "beanName" have to be used with "type".
<jsp:useBean id="name" scope="page|request|session|application" typeSpec />
typeSpec ::= class=�className� |
class=�className� type=�typeName� |
type=�typeName� class=�className� |
beanName=�beanName� type=�typeName� |
type=�typeName� beanName=�beanName� |
type=�typeName�

[This message has been edited by Win Yu (edited November 20, 2001).]
 
Paul Anilprem
Enthuware Software Support
Posts: 4803
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Win, looks like I have to revalidate it. According to this syntax it should not work. I've to check why it worked in my case.
-Paul.
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Anil:
Win, looks like I have to revalidate it. According to this syntax it should not work. I've to check why it worked in my case.
-Paul.


Thanks,Paul.
 
reply
    Bookmark Topic Watch Topic
  • New Topic