1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public static void main(String[] args) { String classpath = System.getProperty("user.dir"); Tomcat tomcat = new Tomcat(); tomcat.setPort(9090); Host host = tomcat.getHost(); host.setName("localhost"); host.setAppBase("webapps");
Context context = tomcat.addContext(host, "/", "classpath "); if(context instanceof StandardContext) { StandardContext standardContext = (StandardContext)context; context .setDefaultContextXml("d:/tomcat/conf/web.xml"); Wrapper wrapper = tomcat.addServlet("/", "DemoServler", new DemoServlet); wrapper.addMapping("/demo.do"); } tomcat.start(); tomcat.getServer().await(); }
|