• 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

<useBean> doubt

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes...but both class and beanName should not be used together
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why?? Please justify your answer

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to reply

Where should I get the API for the JSP standard action tag?
 
deepesh soni
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/products/jsp/reference/api/index.html

this link might help you
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks javez for your concern


Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic