Home  >  Forum  >  Java EE
Post New Query

exception ClassCastException cannot be cast to javax.servlet.Servlet


joined on
November 18,2013
Asked on February 12,2014
Hi  All,
Need help.  I have created a simple test servlet.


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet   {
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println("hello");   
    }
}

But while running getting error as below

SEVERE: Servlet  threw load() exception  ClassCastException  cannot be cast to javax.servlet.Servlet
java.lang.ClassCastException: com.test.TestServlet cannot be cast to javax.servlet.Servlet
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

joined on
October 10,2013
Replied on February 12,2014

Man, check your servlet. You are missing extending  HttpServlet  

public class TestServlet extends HttpServlet   {
}

joined on
November 18,2013
Replied on February 12,2014

Oh I missed.

Thanks a lot , I spent my hours.

Write Answer








Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us