Java jetty中的多servlet
我是Jetty的新手,试图通过在线示例程序理解。以下是我使用的示例程序:Java jetty中的多servlet,java,servlets,jetty-9,Java,Servlets,Jetty 9,我是Jetty的新手,试图通过在线示例程序理解。以下是我使用的示例程序: public class EmbeddedJettyMain { public static void main(String[] args) throws Exception { Server server = new Server(7070); ServletContextHandler handler = new ServletContextHandler(server,
public class EmbeddedJettyMain {
public static void main(String[] args) throws Exception {
Server server = new Server(7070);
ServletContextHandler handler = new ServletContextHandler(server, "/example");
handler.addServlet(ExampleServlet.class, "/");
server.start();
}
}
有了这些,我可以使用:
现在我想再添加一个servlet URI
我该怎么做
我可以看到一些参考,如webapp,寻找一个好的方法
Server server = new Server(7070);
ServletContextHandler handler = new ServletContextHandler(server, "/");
handler.addServlet(ExampleServlet.class, "/example");
handler.addServlet(ExampleServlet.class, "/example2");
每个addServlet创建一个映射。Jetty将为每个映射创建一个单独的Servlet实例,这意味着在每个实例中只调用一次init(ServletConfig config),对映射的所有请求都将转到同一个实例
Jetty提供了一个Web服务器和javax.servlet容器
您的servlet通过jetty的嵌入式容器进行存储和服务,以便在需要时提供服务