使用嵌入式码头和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>