为什么我会收到HTTP Internal 500 Error?

时间:2018-07-05 11:58:14

标签: java eclipse tomcat servlets

我创建了一个动态Web项目。我已经安装了Tomcat 8.5来运行它。 这是我的代码:

SimpleServlet.java

package servletPkg;

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 SimpleServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        System.out.println("hello from get()");
        PrintWriter writer = response.getWriter();
        writer.println("<h3>Hello in html</h3>");
    }   
}

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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>SimpleServletProject</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  <servlet>
  <servlet-name>SimpleServlet</servlet-name>
  <servlet-class>servletPkg.SimpleServlet</servlet-class>
  </servlet> 
  <servlet-mapping>
  <servlet-name>SimpleServlet</servlet-name>
  <url-pattern>/SimpleServlet</url-pattern>
  </servlet-mapping> 
</web-app>

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title> Web  Application</title>
</head>
<body>
Simple Web Application !HELLO
</body>
</html>

http://localhost:8080/SimpleServletProject/---upto这是正确执行的 o / p-简单的Web应用程序!HELLO

http://localhost:8080/SimpleServletProject/SimpleServlet----here我收到HTTP Status 500 – Internal Server Error javax.servlet.ServletException:实例化servlet类[servletPkg.SimpleServlet]

时出错

0 个答案:

没有答案