我寫了一個ContextHandler中映射http://hostname:9001/gm/test
如下:如何添加父上下文在碼頭
public static void main(String[] args) throws Exception {
Server server = new Server(new QueuedThreadPool(8, 6));
ServerConnector connector = new ServerConnector(server);
connector.setPort(9001);
server.setConnectors(new Connector[] { connector });
HandlerCollection handler = new HandlerCollection();
ContextHandler contextHandler = new ContextHandler("/gm");
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[] { new TestHandler("/test") });
contextHandler.setHandler(contexts);
handler.setHandlers(new Handler[] { contextHandler, new DefaultHandler() });
server.setHandler(handler);
server.start();
server.dumpStdErr();
server.join();
}
,但它不工作。如果我在代碼中刪除var contextHandler。請求http://localhost:9001/test
它的工作。調用Testhandle.doHandle()。如果我想將Context上下文路徑添加到ContextHandlerCollection中的所有contextHandlers中,該怎麼做?
謝謝您的回答! – nealons 2014-11-06 12:03:38