You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Rees <dr...@ebetinc.com> on 2000/11/30 02:30:22 UTC

Tomcat 3.2b8 ClassCastException after servlet update

Hi,

I've got a problem where I'm doing a HttpServletRequest.getAttribute in
a servlet after a JSP forwards the request to it.  Here's a basic
outline of what happens:

test.jsp POSTs to forward.jsp (which stores the form info in a
test.TestBean) which then forwards the request to TestServlet.

This only happens when the servlet has been modified, shutting down and
restarting Tomcat allows the servlet to work properly.  Here's the stack
trace:

java.lang.ClassCastException: test.TestBean
        at TestServlet.doPost(TestServlet.java:11)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.facade.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:194)
        at
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:421)
        at
test._0002ftest_0002fforward_0002ejspforward_jsp_0._jspService(_0002ftest_0002fforward_0002ejspforward_jsp_0.java:96)
        at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
        at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
        at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:479)

And the line 11 of the servlet where the exception occurs:
	test.TestBean tb = (test.TestBean)req.getAttribute("testBean");

I have a simple test case (which this was generated under) which I can
post to the list if anyone is interested.

Is this a known bug?  I haven't tried the same thing under Tomcat 3.1
yet, as I was under the impression that Tomcat 3.2beta was superior to
Tomcat 3.1.

Thanks,
Dave

RE: Tomcat 3.2 ClassCastException after servlet update on getAttribute

Posted by David Rees <dr...@ebetinc.com>.
Hi Craig,

> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
>
> David Rees wrote:
>
> > I also just tried this on Tomcat 3.2, same problem.
> >
> > Again, here's the problem:
> >
> > I have a form which posts to a jsp, which then instantiates a
> bean with the
> > data from the form, which then forwards the request to a
> servlet which does
> > a getAttribute to obtain then the bean data.  It then forwards
> on again to
> > another jsp.
> >
> > The problem occurs during development:  Updating the servlet causes a
> > ClassCastException.  Shutting down and restarting Tomcat makes the
> > ClassCastException go away.
> >
> > This happens on Tomcat 3.1 and 3.2.  It does not happen on the
> Tomcat 4.0 m4
> > build.
> >
> > Should I post this issue to the -dev list?  It seems like a
> Tomcat bug to
> > me.
>
> You can if you want ... but there are fundamental architectural
> problems to the
> way that class reloading was done in 3.1 and 3.2.  It would be a
> pretty major
> change to fix it.

Ah, so is this a known bug?  I looked through the archive, but couldn't find
any reference to it.  I would think that what I'm trying to do is pretty
common, I'm surprised it hasn't come up more often.  Is there any known
workarounds besides restarting the server?  It's a very strange bug, casting
the Bean to an object and running Class.forName() reports the right thing...

> Tomcat 4.0 uses a different strategy (pretty much based on what
> Apache JServ)
> did that seems to deal with class reloading in a much more robust
> manner (and
> with lower overhead).

Yeah, I noticed that 4.0 seems to be much quicker when it comes to compiling
and reloading things.  I guess I could run the latest milestone build of
that to avoid this problem.

Thanks,
-Dave


Re: Tomcat 3.2 ClassCastException after servlet update on getAttribute

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
David Rees wrote:

> I also just tried this on Tomcat 3.2, same problem.
>
> Again, here's the problem:
>
> I have a form which posts to a jsp, which then instantiates a bean with the
> data from the form, which then forwards the request to a servlet which does
> a getAttribute to obtain then the bean data.  It then forwards on again to
> another jsp.
>
> The problem occurs during development:  Updating the servlet causes a
> ClassCastException.  Shutting down and restarting Tomcat makes the
> ClassCastException go away.
>
> This happens on Tomcat 3.1 and 3.2.  It does not happen on the Tomcat 4.0 m4
> build.
>
> Should I post this issue to the -dev list?  It seems like a Tomcat bug to
> me.
>

You can if you want ... but there are fundamental architectural problems to the
way that class reloading was done in 3.1 and 3.2.  It would be a pretty major
change to fix it.

Tomcat 4.0 uses a different strategy (pretty much based on what Apache JServ)
did that seems to deal with class reloading in a much more robust manner (and
with lower overhead).

>
> -Dave

Craig McClanahan

Tomcat 3.2 ClassCastException after servlet update on getAttribute

Posted by David Rees <dr...@ebetinc.com>.
I also just tried this on Tomcat 3.2, same problem.

Again, here's the problem:

I have a form which posts to a jsp, which then instantiates a bean with the
data from the form, which then forwards the request to a servlet which does
a getAttribute to obtain then the bean data.  It then forwards on again to
another jsp.

The problem occurs during development:  Updating the servlet causes a
ClassCastException.  Shutting down and restarting Tomcat makes the
ClassCastException go away.

This happens on Tomcat 3.1 and 3.2.  It does not happen on the Tomcat 4.0 m4
build.

Should I post this issue to the -dev list?  It seems like a Tomcat bug to
me.

-Dave

> Replying to my own message:
>
> I just downloaded and tried it under Tomcat 3.1 which showed the same
> problem.  So at least this isn't a new bug.  :-)
>
> I also tried Tomcat 4.0-m4 which works perfectly in for my test case.
>
> > I have a simple test case (which this was generated under) which I can
> > post to the list if anyone is interested.
> >
> > Is this a known bug?  I haven't tried the same thing under Tomcat 3.1
> > yet, as I was under the impression that Tomcat 3.2beta was superior to
> > Tomcat 3.1.
>


RE: Tomcat 3.2b8 ClassCastException after servlet update

Posted by David Rees <dr...@ebetinc.com>.
Replying to my own message:

I just downloaded and tried it under Tomcat 3.1 which showed the same
problem.  So at least this isn't a new bug.  :-)

I also tried Tomcat 4.0-m4 which works perfectly in for my test case.

-Dave

> I have a simple test case (which this was generated under) which I can
> post to the list if anyone is interested.
>
> Is this a known bug?  I haven't tried the same thing under Tomcat 3.1
> yet, as I was under the impression that Tomcat 3.2beta was superior to
> Tomcat 3.1.