0
嵌入式碼頭在應用程序中跟隨代碼,但不能請求成功。 它永遠等待。嵌入式碼頭不能連接
public static class TestHandler extends ContextHandler {
public TestHandler(String contextPath) {
super(contextPath);
}
@Override
public void doHandle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
super.doHandle(target, baseRequest, request, response);
System.out.println("");
}
}
public static void main(String[] args) throws Exception {
Server server = new Server(new QueuedThreadPool(5, 4));
ServerConnector connector = new ServerConnector(server);
connector.setPort(9001);
server.setConnectors(new Connector[] { connector });
HandlerCollection handler = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { new TestHandler("/test") });
handler.setHandlers(new Handler[] { contexts, new DefaultHandler() });
server.setHandler(handler);
server.start();
server.dumpStdErr();
server.join();
}
但改變了服務器的contstructor到另一個,它會好的,有人可以解釋原因嗎? 我跟蹤代碼,找不到原因。謝謝!!
public static void main(String[] args) throws Exception {
Server server = new Server(9001);
// Server server = new Server(new QueuedThreadPool(5, 4));
// ServerConnector connector = new ServerConnector(server);
// connector.setPort(9001);
// server.setConnectors(new Connector[] { connector });
HandlerCollection handler = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { new TestHandler("/test") });
handler.setHandlers(new Handler[] { contexts, new DefaultHandler() });
server.setHandler(handler);
server.start();
server.dumpStdErr();
server.join();
}
PS:帶碼頭服務器9.1.0.M0版本
我瓚ge日誌級別爲DEBUG,沒有找到消息,哪個java文件用這個消息存在?謝謝 – nealons 2014-11-05 10:09:07
我使用Slf4J + Logback作爲日誌框架。我認爲你的應用程序的一些消息沒有被記錄,請參閱[這裏](http://www.eclipse.org/jetty/documentation/current/configuring-logging.html#selecting-log-framework)。 – Stefan 2014-11-05 10:15:16
我也用slf4j + logback – nealons 2014-11-05 10:16:42