1 Reply Latest reply on Aug 29, 2011 1:56 PM by 885069

    Servlet 3.0 server specifications

      Hi, i'm italian and sorry for my bad english.
      I'm trying new servlet features expecially the "pluggability".(8.1.4 @WebListener)
      In tutorial i can see this example:
      public class MyListener implements ServletContextListener{
      public void contextInitialized(ServletContextEvent sce) {
      ServletContext sc = sce.getServletContext();
      sc.addServlet("myServlet", "Sample servlet",
      "foo.bar.MyServlet", null, -1);
      sc.addServletMapping("myServlet", new String[] {
      "/urlpattern/*" });
      however searching in API, function "addServlet" has two param instead four and "addServletMapping" daesn't exist.
      I tryed with addServlet's right parameters and as I imagined, web.xml result corrupted when addServletMapping is called
      how solve this problems?
        • 1. Re: Servlet 3.0 server specifications
          solved, i found the right code

          import javax.servlet.ServletContext;
          import javax.servlet.ServletContextEvent;
          import javax.servlet.ServletContextListener;
          import javax.servlet.ServletRegistration;
          import javax.servlet.annotation.WebListener;
          public class WebXmlManager implements ServletContextListener {
               public void contextInitialized(ServletContextEvent arg0) {
                    ServletContext context = arg0.getServletContext();
                    ServletRegistration.Dynamic dynamic = context.addServlet("test","core.Test");
          however there isn't any way to run the Programmatic definition of component for each request? i receive this exception : "Servlets can not be added to context /app as the context has been initialised"

          Edited by: Jstar on 29-ago-2011 6.55

          Edited by: Jstar on 29-ago-2011 6.56