【发布时间】:2015-08-04 17:01:32
【问题描述】:
我是 Servlet 的新手。无论如何,我的服务器运行得很好,我可以访问我的 index.html 并且一切正常,但是当我尝试在服务器上运行我的 servlet 时,它给了我 404 错误
我尝试了 tp restart server,编辑 web.xml 文件但没有运气,同样的问题也有一些关于 SO 的旧问题,但都与我的情况不同。试过urlPatters{"/SimpleServlet"}也没有运气..
在装有 Eclipse Luna 和 tomcat7 的 Linux 机器上运行。
这是我的 servlet
package com.bgt.zaa;
import java.io.IOException;
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 World");
}
}
这是我的 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>SinmpleServletProject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
错误:
【问题讨论】:
-
你的 servlet 编译是否正常并生成了它的类?
-
是的,类文件已生成,但仍然......
标签: eclipse tomcat servlets tomcat7 http-status-code-404