1

我正在尝试使用 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 或只使用嵌入式码头

4

2 回答 2

1

对于它的价值,我使用 Jetty 和 NetBeans,我不使用 NetBeans 来运行码头服务器。相反,我使用mvn jetty:run.

我认为您的问题是您没有指定 servlet 来处理web.xml文件中的请求。Java 代码大多是无关紧要的。

于 2013-03-09T23:36:41.673 回答
0

您的 webapp 在上下文中http://localhost:8080/My_WS/

您的 Servlet 位于http://localhost:8080/My_WS/My_Servlet

您看到的错误来自您的点击http://localhost:8080/,它没有设置为对您的简单场景执行任何操作。

于 2013-03-10T01:00:48.577 回答