barnarp
asked on
ClassCastException
Hi,
I keep getting a java.lang.ClassCastExcepti on 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("max login.jsp" );
%>
Bean code:
public void LogoffFromDb () throws Exception
{
if (GlobalConn != null) {
try {
GlobalConn.close();
}
catch (Exception ignored) {}
}
}
Regards
I keep getting a java.lang.ClassCastExcepti
<jsp:useBean id="db" scope="session" class="dbpackage.dbbean" />
<%
db.LogoffFromDb();
session.invalidate();
response.sendRedirect("max
%>
Bean code:
public void LogoffFromDb () throws Exception
{
if (GlobalConn != null) {
try {
GlobalConn.close();
}
catch (Exception ignored) {}
}
}
Regards
ASKER
Thanks,
yes there is such a class which I also use in other pages, and it is a bean.
yes there is such a class which I also use in other pages, and it is a bean.
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?
<%
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?
ASKER
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
db was also the name of another session variable which was type String.
That's why the cast error.
Thanks for the help
that would do it ;-)
glad you got it sorted :-)
Tim
glad you got it sorted :-)
Tim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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