开发者

Embedded Jetty handles each message twice

I'm trying to use Jetty in the simplest way possible. I have started by running the walkthrough from the Jetty@Eclipse documentation, which basically looks like that:

public class Main {

    public class HelloHandler extends AbstractHandler
    {
        public void handle(String target,Request baseRequest,HttpServletRequest     request,HttpServletResponse response)
            throws IOException, ServletException
        {
            response.setContentType("text/html;charset=utf-8");
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);
            response.getWriter().println("<h1>Hello World</h1>");
        }
    }

    private void run() throws Exception
    {
        Server server = new Server(8080);
        server.setHandler(new HelloHandler());
        server.start();
        server.join();
    }

    public static void main(String[] args) throws Exception
    {
        Main m = new Main();
        m.run();
    }
}

The problem is that the handler gets called twice on every request. I'm using Chrome with http://localhost:8080 to simulate, if that makes any difference. Jetty is embedded as two jars:

What am I doing wrong/missing here?


Turns out Chrome was "to blame". I wasn't getting the same HTTP request, I was getting the original HTTP request in addition to a request for /favicon.ico. All looks OK as far as Jetty is concerned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜