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

14,564

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.

Share:
14,564
rec
Author by

rec

Hi Tony! hehe!

Updated on June 13, 2022

Comments

  • rec
    rec almost 2 years

    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.