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:
- jetty-all-7.0.2.v20100331.jar
- servlet-api-开发者_如何学C2.5.jar
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.
精彩评论