There is no standard Servlet API to accomplish this.
You can do this in Tomcat. In your webapp, your master servlet (the one creates others) must implements ContainerServlet
so you can get hold of the Wrapper
object. Once you have your class file installed, you can make following calls,
Context context = (Context) wrapper.getParent();
Wrapper newWrapper = context.createWrapper();
newWrapper.setName(name);
newWrapper.setLoadOnStartup(1);
newWrapper.setServletClass(servletClass);
context.addChild(newWrapper);
context.addServletMapping(pattern, name);
These calls create a servlet on the fly. You need to find way to persist this information. You can do this by updating web.xml or write to your own file.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…