使用嵌入式码头和servletcontexthandler时,是否可以设置servlet名称?

时间:2018-12-21 07:12:27

标签: java jax-rs jetty embedded-jetty

使用嵌入式码头和servletcontexthandler时如何设置servlet名称,就像我们在带有servlet映射的web xml中所做的一样?

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
            /*
             * code to enable startup listeners
             */
            StartupListener sup = new StartupListener();
            context.addEventListener(sup);
            context.setContextPath("/JettyApp");

            Server jettyServer = new Server(8081);
            jettyServer.setHandler(context);
            ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
            jerseyServlet.setInitOrder(0);

就像在web.xml中一样

<servlet-mapping>
    <servlet-name>WebDemo</servlet-name>
    <url-pattern>/App/Service/*</url-pattern>
  </servlet-mapping>

0 个答案:

没有答案