在servow中添加更多servlet到servlet构建器

时间:2015-01-20 21:30:37

标签: java servlets undertow

我有这个代码添加servlet和url

        DeploymentInfo servletBuilder = deployment()
                .setClassLoader(ServletServer.class.getClassLoader())
                .setContextPath(MYAPP)
                .setDeploymentName("test.war")
                .addServlets(
                        servlet("MyServlet", MessageServlet.class)
                        .addInitParam("message", "My own Servlet")
                        .addMapping("/myservlet"));

        DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
        manager.deploy();

        HttpHandler servletHandler = manager.start();
        PathHandler path = Handlers.path(Handlers.redirect(MYAPP))
                .addPrefixPath(MYAPP, servletHandler);
        Undertow server = Undertow.builder()
                .addHttpListener(8080, "localhost")
                .setHandler(path)
                .build();
        server.start();  

但是,我尝试使用此版本,但它无效

I have this code that add servlet, and the url

.addServlets(servlet("MyServlet", MessageServlet.class)
  .addInitParam("message", "My own Servlet")
  .addMapping("/myservlet"));

这不起作用,因为后者的servlet(url)部分正在工作,而前者没有。我的意思是myservlet1正在工作,而myservlet不再工作了

0 个答案:

没有答案