Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

ClassCastException

Hi,

I keep getting a java.lang.ClassCastException exception on the following page and don't know why.

<jsp:useBean id="db" scope="session" class="dbpackage.dbbean" />
<%
db.LogoffFromDb();
session.invalidate();
response.sendRedirect("maxlogin.jsp");
%>

Bean code:

public void LogoffFromDb () throws Exception
{
if (GlobalConn != null) {
      try {
         GlobalConn.close();
         }
      catch (Exception ignored) {}
      }

}

Regards
0
barnarp
Asked:
barnarp
  • 3
  • 2
1 Solution
 
TimYatesCommented:
>> <jsp:useBean id="db" scope="session" class="dbpackage.dbbean" />

I'm guessing this is causing it...

is there a class dbpackage.dbbean?

is it a bean?

Can I also suggest (as a sideline) that classes should start with a Capital Letter, and methods with a small letter...

That tends to be the norm, and makes your code much more easily readable and understandable :-)

Tim
0
 
barnarpAuthor Commented:
Thanks,

yes there is such a class which I also use in other pages, and it is a bean.
0
 
TimYatesCommented:
Can you put:

<%
   Object o = session.getAttribute( "db" ) ;
   if( o != null )  
       out.println( db.getClass().getName() ) ;
%>

to see what the attribute in the session actually is?

I assume you do a similar bit of code on other pages...  can you compare them to this?

What's the difference?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
barnarpAuthor Commented:
Found the problem.

db was also the name of another session variable which was type String.

That's why the cast error.

Thanks for the help
0
 
TimYatesCommented:
that would do it ;-)

glad you got it sorted :-)

Tim
0
 
moduloCommented:
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now