我試圖以動態從外部文件中增加一個servlet(編譯.class文件)上運行tomcat7服務器動態地從外部文件中添加的servlet,Tomcat7
這裏是我的代碼
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRegistration;
import com.sun.org.apache.bcel.internal.util.ClassLoaderRepository;
public class ConListenerImlp implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
ServletContext context = arg0.getServletContext();
final ServletRegistration.Dynamic dn=context.addServlet("test","C:\\Users\\Learning\\workspace\\Server\\build\\classes\\Test.class");
dn.setAsyncSupported(true);
dn.addMapping("/test");
}
}
我的呼喚servlet的 「測試」 我得到一個ClassNotFoundException
java.lang.ClassNotFoundException: C:\Users\Learning\workspace\Server\build\classes\Test.class
任何幫助將是非常讚賞
請閱讀[Javadoc](http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#addServlet(java.lang.String,javax.servlet.Servlet))方法。它解決您的擔憂。 – NINCOMPOOP