muscleman415 德邦物流 专员  2017年04月14日
500异常:Class com.netease.QueryServlet is not a Servlet
各位大神,我今天在写一个简单的servlet并用maven部署时,浏览器发请求报500异常:Class com.netease.QueryServlet is not a Servlet
但是同样的源码和web.xml配置放在tomcat里直接启动可以访问,源码和web.xml配置如下
和论坛里类似的问题不一样,我的类是继承了HttpServlet的。不知道问题出在哪额?


package com.netease;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class QueryServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
response.setCharacterEncoding("UTF-8");
PrintWriter writer= response.getWriter();
String title = request.getParameter("title");
if (title==null){
title="默认";
}

Dbquery.dbpoolInit();
Dbquery db=new Dbquery();
String content= db.dbpoolTest(title);
writer.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
writer.println("<html><body>");
writer.println("<h1>Poem is "+content+title+"</h1>");
writer.println("</body></html>");

}

}



web.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0">
<display-name>Restaurant</display-name>
<servlet>
<servlet-name>query</servlet-name>
<servlet-class>
com.netease.QueryServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>query</servlet-name>
<url-pattern>/query</url-pattern>
</servlet-mapping>
</web-app>

控制台抛异常:
java.lang.ClassCastException: com.netease.QueryServlet cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
...全文
75 点赞 收藏 4
写回复
4 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告