我正在尝试使用 Jetty 与 Eclipse 一起做超级简单的“Hello World”Servlet。
我有一个正在工作的 Jetty 服务器适配器,但是当我尝试在我的服务器上启动时,出现以下错误;
小服务程序代码:
package My;
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 My_Servlet
*/
@WebServlet("/My_Servlet")
public class My_Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public My_Servlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().println("<html><body><h1>My Servlet</h1></body></html>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
我得到的错误:
Error 404 - Not Found.
No context on this server matched or handled this request.
Contexts known to this server are:
/My_WS ---> o.e.j.w.WebAppContext{/My_WS,file:/home/user/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/My_WS/},/home/user/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/My_WS [failed]
那就是我在 localhost:8080 上看到的。
提前感谢您的帮助,盖伊
编辑
我注意到我想念 classVisitor(Spring 框架的一部分),并且为了支持我的简单程序变得很麻烦。我可能会切换到 tomcat 或只使用嵌入式码头