-1

我开发了一个简单的servlet,如下所示..通过在eclipse中选择dynamci项目在eclipse中......

小服务程序是..

package com.demo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

    public class Myservlet2 extends HttpServlet {
        private static final long serialVersionUID = 1L;


        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            System.out.println("Servlet 2 of App2 invoked...");
             response.setContentType("text/html");
             PrintWriter out=response.getWriter();
             out.println("This output is generated by servlet2 of app2");
             out.close();

        }
    }

而 web.xml 是......

 <servlet>
<servlet-name>Myservlet2</servlet-name>
<servlet-class>com.demo.Myservlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Myservlet2</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>

通过eclipse将它部署到tomcat上后,出现以下错误。

java.lang.ClassNotFoundException: com.demo.Myservlet2
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

请如何纠正。在此先感谢

4

1 回答 1

0

检查该类com.demo.MyServlet2是否存在于WEB-INF/classes或位于位于的库 jar 中WEB-INF/lib

于 2012-07-14T18:58:50.840 回答