2013年8月4日星期日

cannot be cast to javax.servlet.Servlet

Just beginning to learn to write a simple servlet:
question is: Jcreator compiled by, but appears in the browser after release
root cause

java.lang.ClassCastException: com.tsinghua.Hello cannot be cast to javax.servlet.Servlet
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 102)
org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java: 293)
org.apache.coyote.http11.Http11Processor.process (Http11Processor.java: 859)
org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process (Http11Protocol.java: 602)
org.apache.tomcat.util.net.JIoEndpoint $ Worker.run (JIoEndpoint.java: 489)
java.lang.Thread.run (Thread.java: 619)


I ask what the problem ah?
public class Hello {

public void init (ServletConfig parm1) throws ServletException {
/ / TODO: Add your code here
System.out.println ("init it");

}


public ServletConfig getServletConfig () {
/ / TODO: Add your code here
return null;
}



public void service (ServletRequest req, ServletResponse res) throws ServletException, IOException {
/ / TODO: Add your code here
System.out.println ("sdfjsdf");
PrintWriter pw = res.getWriter ();
pw.println ("helle");


}


public String getServletInfo () {
/ / TODO: Add your code here
return "";
}


public void destroy () {
/ / TODO: Add your code here
System.out.println ("destroy");

}

}
------ Solution ----------------------------------- ---------
public class Hello exterds HttpServlet {

------ For reference only ---------------------------------- -----
great, thank you pull ~ ~ ~ ~ ~ I actually did not pay attention to see this
------ For reference only ------------ ---------------------------
floor Positive Solutions
------ For reference only ----- ----------------------------------
help to
------ For reference only ---------------------------------------
gravedigger, but also to find me The answer, thank God, thank Baidu big csdn
------ For reference only --------------------------- ------------
also encountered this problem, but also find the answer

没有评论:

发表评论