aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes useBean problem ? 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 problem ?" Watch "useBean problem ?" New topic
Author

useBean problem ?

Deepinder S Narang
Greenhorn

Joined: Sep 05, 2006
Posts: 21
Hello Friends

When i use the below code for testing :

<jsp:useBean id="DB1" class="com.example.model.DBNameForJSP" scope="application" >
<jsp:setProperty name="DB1" property="DBName" value="Narang" />
</jsp:useBean>

<b> The DB name stored in JSP is : </b><jsp:getProperty name="DB1" property="DBName"/>

it gives me Class Cast Exception. And it doesnt create an bean for me.

But when i set the attribute using the foll:

<%@ page import="com.example.model.*" %>

<% DBNameForJSP db=new DBNameForJSP();
db.setDBName();
getServletContext().setAttribute("DB1",db); %>

The useBean works fine for. Why when used without the above scriptlet it gives me class cast exception ?

Please help ! Thanks in advance !
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Can you list full stack trace of your exception and explain a bit more about the issue.

Also change your property name from "DBName" to "dbName" and setter/getter would be setDbName(String) and getDbName()
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Are you sure there's no other "DB1" variable in the application scope ?
Try to output it before the useBean : ${applicationScope.DB1}

Using useBean with the class attribute will make a new bean if there's not already one in the specified scope. I suppose that there might be already one in application scope, and trying to cast it to DBNameForJSP fails.


[My Blog]
All roads lead to JavaRanch
Deepinder S Narang
Greenhorn

Joined: Sep 05, 2006
Posts: 21
Hello Friends

Thanks for the effort ! The bean wasnt set properly so was getting the error. Now its working

Regards
Deepinder
 
wood burning stoves
 
subject: useBean problem ?