java.lang.ClassCastException cannot be cast to javax.servlet.ServletException

15.2k views Asked by At

I'm trying to deploy a java application to appspot (google appengine). I'm new to java, so bear with me. When I run the application locally from eclipse, it runs fine. After uploading it to google appspot, I get an error (only in one of the .jsp pages, other .jsp pages work fine). The error log says:

   Uncaught exception from servlet

java.lang.ClassCastException: java.lang.ClassCastException cannot be cast to javax.servlet.ServletException
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:754)

Can somebody shed some light on this issue? What could be wrong in this particular page? If you would like to see the page code, let me know.

2

There are 2 answers

0
jheddings On BEST ANSWER

It looks like something in your code is throwing an exception that does not derive from ServletException. A handler upstream is catching that exception and (possibly) trying to do something intelligent with it.

There is probably another underlying issue causing the exception to be thrown in the first place, but that might be revealed by seeing first what the exception is.

If you aren't sure where this exception is, try wrapping you entire page handler in a try ... catch block, looking for all Throwable's. When you find one, rethrow it inside of a ServletException:

try {
    // handle page request
} catch (Throwable t) {
    throw new ServletException(t);
}

This should allow the web server to display the exception so you can continue tracking down the problem. Note that this should probably be temporary code.

0
lrkwz On

Look for instances of javax.servlet.ServletException.class in your WEB-INF/lib. Contents for servler.jar or servlet.api.jar should be provided bye the container and should not appear in your WAR file.