• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

useBean problem ?  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepinder S Narang
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends

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

Regards
Deepinder
 
Danger, 10,000 volts, very electic .... tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!