eclipse中的ServletException:实例化servlet类时出错[Pkg.hello]

时间:2017-06-29 11:05:51

标签: java servlets

enter image description here

错误

  

抛出java.lang.ClassNotFoundException:Pkg.hello      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)      org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)      org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)      org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)      org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:861)      org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1455)      org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)      java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)      java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)      org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)      java.lang.Thread.run(Unknown Source)在这里输入代码注意完整      服务器日志中提供了根本原因的堆栈跟踪。

Web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
version="3.1"> <display-name>Firstproj</display-name> <servlet>
<servlet-name>abc</servlet-name>
<servlet-class>Pkg.hello</servlet-class> </servlet> <servlet-mapping>
<servlet-name>abc</servlet-name> <url-pattern>/welcome</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file> </welcome-file-list>
</web-app>  

hello.java

package Pkg; 

import java.io.IOException;
import javax.servlet.Servlet; 
import javax.servlet.ServletConfig;
import javax.servlet.ServletException; 
import javax.servlet.ServletRequest; 
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
/** * Servlet
implementation class hello */
@WebServlet("/welcome") 
public class hello implements Servlet {
    @Override 
    public void destroy() { 
        // TODO Auto-generated method stub 
    } 

    @Override 
    public ServletConfig   getServletConfig() 
    {
        // TODO Auto-generated method stub return null;
    }

    @Override 
    public String getServletInfo() {
        // TODO Auto-generated method stub 
        return null; 
    } 

    @Override 
    public void init(ServletConfig arg0) throws ServletException { 
        // TODO Auto-generated method stub 
    }

    @Override 
    public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
        // TODO Auto-generated method stub 
        System.out.println("faisal"); 
    }
} 

0 个答案:

没有答案