404错误tomcat 7 Java Servlet

时间:2016-01-10 21:40:26

标签: java servlets tomcat7 http-status-code-404

所以我一直在撞墙挡住我的头。

我在Tomcat 7 servlets上学习了本教程:https://www.youtube.com/watch?v=bKaNotLIGqE

但是当我运行servlet时出现404错误。该视频声称描述符文件不需要服务器映射,因为tomcat 7负责处理它。

我的servlet:

package com.helloworld.servlets;

import java.io.*;
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 HelloWorld
 */
@WebServlet("/HelloWorld")
public class HelloWorld extends HttpServlet {
    private static final long serialVersionUID = 1L;

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

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter out = response.getWriter();
        out.println("<html><body><h1>Hello From Chris </body></html>");

    }

我的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>HellowWorlServlet</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>
  >
</web-app>

错误讯息:

HTTP状态404 - / HellowWorlServlet / HelloWorld

输入状态报告

message / HellowWorlServlet / HelloWorld

说明请求的资源不可用。

全神贯注地表达你的想法。感谢

0 个答案:

没有答案
相关问题