Error loading class
807569Sep 12 2006 — edited Sep 12 2006Hi, I've got the following code to call some classes I've created:
String className = this.request.getParameter("class_name");
className = (className==null?"":className.trim());
MySession.setAttribute(this.request, "class_name", className);
try {
Class cl = Class.forName(className);
Class pt[] = {Class.forName("javax.servlet.http.HttpServletRequest"),
Class.forName("java.io.PrintWriter")};
java.lang.reflect.Constructor cons = cl.getConstructor(pt);
Object obj[] = {this.request, this.out};
Object cont = cons.newInstance(obj);
s = ((AppHtml)cont).getHtml();
} catch (java.lang.Exception ex) {
ex.printStackTrace();
s = ex.getMessage() + "\n";
s += "Error in instance" + className + "<";
}
The problem I have is each time I try to call a class that is in the same project a classnotfound exception is thrown.
java.lang.ClassNotFoundException: AgrProducto
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
What do I need to load a class with the code above? Thanks in advance