wood burning stoves 2.0*
The moose likes JSP and the fly likes Problem with the jsp:useBean tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with the jsp:useBean tag" Watch "Problem with the jsp:useBean tag" New topic
Author

Problem with the jsp:useBean tag

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello sir, madam

Information :
---------------------------------------------------------------------------
AddressBean.java

package businessData.visitorAddresses;
public class AddressBean implements java.io.Serializable
{
private String _name;

public void setName(String name)
{
_name=name;
}
public String getName()
{
return _name;
}
}
---------------------------------------------------------------------------

useBean.jsp

<%@ page import="businessData.visitorAddresses.*"%>

<jsp:useBean id="abc" beanName="AddressBean" type="AddressBean">
<jsp:setProperty name="abc" property="name" value="Ram"/>
</jsp:useBean>

<jsp:getProperty name="abc" property="name"/>  <b> : </b>

---------------------------------------------------------------------------

Problem :

Even if I have imported all the classes from businessData.visitorAddresses package in the page directive still I get a ClassNotFoundException for AddressBean class. However if I give the fully qualified name of the class in the beanName attribute then it works fine.

Findings :

If I use <...class="AddressBean" type="AddressBean"> I get above exception

If I use <...class="businessData.visitorAddresses.AddressBean" type="AddressBean"> I get desired output and no exception

If I use <...beanName="AddressBean" type="AddressBean">I get exception

If I use <...beanName="businessData.visitorAddresses.AddressBean" type="AddressBean"> I get exception

If I use <...beanName="businessData.visitorAddresses.AddressBean" type="businessData.visitorAddresses.AddressBean"> I get desired output.

I dont know why this is happening ?

Can anyone please help me with this problem ?

Waiting for your suggestions.

Thanks and Regards
Rohit.

[ November 24, 2005: Message edited by: Rohit Bhagwat ]
[ November 24, 2005: Message edited by: Rohit Bhagwat ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

In all cases where it didn't work, your type wasn't fully qualified.
In the cases where it worked, they were.

The classloaded needs the package in order to find your bean.

type="businessData.visitorAddresses.AddressBean"


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Originally posted by Ben Souther:
In all cases where it didn't work, your type wasn't fully qualified.


But if you refer to second findings above. Then in that case I dont have fully qualified type but still it worked.

My second question is ultimately jsp is converted to servlets and in that case if you look at the code of generated servlets then we have the import statement inserted properly but still it is not able to get the class.
The exception which I am getting is ClassNotFoundException which means it is a runtime exception. The import statement is resolved and it also gets the AddressBean ,otherwise it would have resulted in compile time errors and not runtime exception.

I guess this is a bug with the useBean as they might have not considered the import statement in the page directive and hence may be they have made a complusion of fully qualified name in the class and beanName attribute.

I dont know, may be i am wrong !!
[ November 24, 2005: Message edited by: Rohit Bhagwat ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Rohit Bhagwat:

But if you refer to second findings above. Then in that case I dont have fully qualified type but still it worked.


In that case, you fully qualified it in the class attribute.

JSP5.1 in the JSP Spec (see my signature for link) does a nice job of explaining this in pretty plain English (for a spec, anyway).
It's worth reading.
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Originally posted by Ben Souther:
In that case, you fully qualified it in the class attribute.


I went through the specification. Thanks for the link.
What I found after reading the specification is that only for class attribute we should have fully qualified name. I didnt found it for type and beanName in the specification.
However I then refered to java documentation for java.beans.Beans.instantiate method and I found that from the examples provided in the documentation we have to provide the fully qualified name for beanName attribute.

Can you please suggest me the page no in the specifications.pdf file which says that type should have fully qualified name ?

Actually Ben what I wanted to point out is although as per the specification they have mentioned that it should be fully qualified name for the class attribute, however dont you think that it is redundant to again provide the full qualified name of the class even after importing the class ? Usually in java programming we just import the desired class and use the name of the class directly instead of again using the fully qualifed name of the class.

I guess there might some other motive behind this which I am unable to understand

Waiting for your reply...
[ November 24, 2005: Message edited by: Rohit Bhagwat ]
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Also I have not understood the line from specification for the id attribute
"client request processing time."

However we cannot specify request time attribute expression for id attribute.Same applies for class,scope and type attribute.

Can anyone please help me..


Thanks and Regards
Rohit.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I guess there might some other motive behind this which I am unable to understand


I think the motive was to give you one tag that takes care of all the setup.
You don't need to import the class if you've declared it with useBean.
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Yes Ben,
Apart from that I cant think of anyother motives !!

Thanks for your reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with the jsp:useBean tag
 
Similar Threads
jsp:useBean question
Doubt in jsp:useBean attribute 'type'
jsp:useBean
Scope of jsp:useBean
jsp:useBean