Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jetty中的多servlet_Java_Servlets_Jetty 9 - Fatal编程技术网

Java jetty中的多servlet

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,

我是Jetty的新手,试图通过在线示例程序理解。以下是我使用的示例程序:

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的嵌入式容器进行存储和服务,以便在需要时提供服务