wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes <useBean> doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "<useBean> doubt" Watch "<useBean> doubt" New topic
Author

<useBean> doubt

Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Which of the following represents a correct syntax for usebean. Select the two correct answers.

A.<jsp:usebean id="fruit scope ="page"/>
B.<jsp:usebean id="fruit type ="String"/>
C.<jsp:usebean id="fruit type ="String" beanName="Fruit"/>
D.<jsp:usebean id="fruit class="Fruit" beanName="Fruit"/>

Ans: B, C
ty
Please make me understand how B, C are the right options. Is beanName attribute is allowed to use only with type attribute??

please justify the given answers


Thanks <br />Poonam Agarwal SCWCD 86%
deepesh soni
Greenhorn

Joined: Jul 13, 2007
Posts: 25
Yes...but both class and beanName should not be used together


scjp 1.4 (90%)
scwcd 5 (88%)
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Why?? Please justify your answer

Vishal Chugh
Ranch Hand

Joined: Oct 27, 2007
Posts: 177
No one can justify just because API does .

Is beanName attribute is allowed to use only with type attribute??


Yes , you are correct , beanName cant be used alone , must be used with type only , that also API says.
deepesh soni
Greenhorn

Joined: Jul 13, 2007
Posts: 25
these are the attribute combinations allowed with <jsp:useBean>
class=”className” |
class=”className” type=”typeName” |
type=”typeName” class=”className” |
beanName=”beanName” type=”typeName” |
type=”typeName” beanName=”beanName” |
type=”typeName”
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Thanks to reply

Where should I get the API for the JSP standard action tag?
deepesh soni
Greenhorn

Joined: Jul 13, 2007
Posts: 25
http://java.sun.com/products/jsp/reference/api/index.html

this link might help you
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Thanks deepesh... please help me out to how to read this API to get the information about the JSP standard actions like <jsp:usebean>



Thanks
Janez Novak
Ranch Hand

Joined: Feb 09, 2009
Posts: 31
Surprised that this two works:
B.<jsp:usebean id="fruit" type ="String"/>
C.<jsp:usebean id="fruit" type ="String" beanName="Fruit"/>

I thought that for type and class it has to be fully qualified name.

In my tomcat it works for String in type attribute and not in class attribute. But for custom object from custom package it does not work, you have to provide full class name.

My guess is this is because java.lang package is imported by default.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Is it?? that you have use fully qualified class name for class and type attribute even if you use the <@ page import=""> directive to import the required package??
Janez Novak
Ranch Hand

Joined: Feb 09, 2009
Posts: 31
For type attribute it works:
<%@page import="si.test.*" %>
<jsp:useBean id="dog1" type="Dog" scope="session"></jsp:useBean>

For class attribute above does not work even with import.

jsp 2.0 spec says:
- class attribute
The fully qualified name of the class that defines the
implementation of the object. The class name is case
sensitive. If the class and beanName attributes are not specified the object must be present in the given scope.

- type attribute
If specified, it defines the type of the scripting variable
defined.
This allows the type of the scripting variable to be distinct
from, but related to, the type of the implementation class
specified.
The type is required to be either the class itself, a superclass
of the class, or an interface implemented by the class
specified.
The object referenced is required to be of this type,
otherwise a java.lang.ClassCastException shall occur at
request time when the assignment of the object referenced
to the scripting variable is attempted.
If unspecified, the value is the same as the value of the class
attribute.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Hello javez

could you please help me to read API in correct way. I mean where I find the JSP spec that describe the requirments of using JSP standard action and so???
I have the API but i dont know where to find the related details like if I want to know about the required attributes of a particular directive or action tag OR what kind of value they can accept etc...??


please reply
Janez Novak
Ranch Hand

Joined: Feb 09, 2009
Posts: 31
You can find specs in folowing locations:

Servlet 2.4
http://www.jcp.org/aboutJava/communityprocess/final/jsr154/index.html

JSP 2.0
http://jcp.org/aboutJava/communityprocess/final/jsr152/index.html

JSTL Spec
http://jcp.org/aboutJava/communityprocess/final/jsr052/index2.html

In above links click on download button, that accept licence and you will be able to download pdf version of specs.

Other specification urls
http://faq.javaranch.com/java/SpecificationUrls


Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Thanks javez for your concern


Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <useBean> doubt
 
Similar Threads
Which of the following are correct JSP useBean declarations?
J2EE Certificate qs on useBean
beanName
use Bean query
<jsp:usebean ... action