1、运行的servlet
Server server=new Server(18080);
// 配置Connector
//设置Handler
ServletContextHandler context=new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/wang");//设置上下文(Context Path)
server.setHandler(context);
context.addServlet(new ServletHolder(new FirstServlet()), "/test");
server.start();
server.join();
Server server = new Server(28080);
WebAppContext context = new WebAppContext();
context.setContextPath("/myapp");
context.setDescriptor("F:/webapps//root/WEB-INF/web.xml");
context.setResourceBase("F:/webapps//root");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
server.join();
在浏览器中输入http://localhost:28080/myapp/
就可到达这个的根目录
详情参考http://www.jettycn.com/Jetty/Tutorial/Embedding_Jetty.html