HTTP状态500 - 实例化servlet类java.reg.pkg.Hello时出错

时间:2014-04-07 12:38:39

标签: java servlets

我正在尝试在eclipse中执行servlet程序,但我收到HTTP状态500错误。

请找到我的目录结构:

Practice_servlet        | Java资源        |       SRC        |  javs.reg.pkg        |   Hello.java

我的web.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Practice1_servlet</display-name>
  <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>
  <servlet>
      <servlet-name>Hello1</servlet-name>
    <servlet-class>java.reg.pkg.Hello</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Hello1</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>
</web-app>

我的hello.java程序是:

package java.reg.pkg;

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;

/**
 * Servlet implementation class Hello
 */
public class Hello extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Hello() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("type/html");
        PrintWriter out = response.getWriter();
        out.println("Hello World");
        // TODO Auto-generated method stub
    }

}

知道问题可能是什么?

上述程序的堆栈跟踪:

HTTP状态500 - 实例化servlet类java.reg.pkg.Hello

时出错

输入例外报告

message实例化servlet类java.reg.pkg.Hello

时出错

说明服务器遇到内部错误,导致无法完成此请求。

例外

  

javax.servlet.ServletException:实例化servlet类时出错   java.reg.pkg.Hello     org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)     org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)     org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)     org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:313)     java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)     java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)     java.lang.Thread.run(未知来源)

     

根本原因

     

java.lang.ClassNotFoundException:java.reg.pkg.Hello     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)     org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)     org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)     org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)     org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:313)     java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)     java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)     java.lang.Thread.run(未知来源)

注意Apache Tomcat / 7.0.52日志中提供了根本原因的完整堆栈跟踪。


我正在使用 Apache Tomcat / 7.0.52

2 个答案:

答案 0 :(得分:0)

尝试清理项目并运行。如果您正在使用eclipse Project - &gt;清洁

答案 1 :(得分:-2)

我认为那里有一个错误的名字。您的servlet名为Hello,位于java.reg.pkg,而堆栈跟踪表示已指示在SampleHello包中加载名为java.sample.pkg的servlet。

您提供的web.xml没有后一个servlet的痕迹,因此ClassNotFoundException错误......