无法在tomcat 8.5.15和eclipse jee neon中运行servlet

时间:2017-06-27 19:21:28

标签: java eclipse tomcat servlets web

我已经按照youtube频道上的教程“Java Brains”链接:https://www.youtube.com/watch?v=gU0RebsaFzQ&t=10s并在运行servlet文件时遇到困难。我收到此错误消息:

HTTP状态[404] - [未找到]

输入状态报告

消息 /SimpleServletProject/servlet/org.altamash.careersix.SimpleServlet

说明原始服务器未找到目标资源的当前代表,或者不愿透露该资源是否存在。

我的简单index.html是:

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

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>SimpleServletProject</display-name>
  <servlet>
        <servlet-name>SimpleServlet</servlet-name>
        <servlet-class>SimpleServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>SimpleServlet</servlet-name>
        <url-pattern>/SimpleServlet</url-pattern>
    </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

最后我的servlet文件SimpleServlet.java如下:

package org.altamash.careersix;

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;

/**
 * Servlet implementation class SimpleServlet
 */
@WebServlet("/SimpleServlet")
public class SimpleServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Hello from doGet method");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = response.getWriter();
        writer.println("<h3>Hello in HTML</h3>");
    }

}

请大家帮帮我解决这个问题:( ..谢谢。

0 个答案:

没有答案