I am completely new to servlets. I have an extensive programming background (C, C++, assembler, PHP, python, javascript, others) and I am trying to get into servlet programming. I have done several jsp's and small java apps, and I have code that works both as a java app and as a jsp:
No problem when I compile and run. Even as a jsp, it's not a problem:
That also works perfectly fine. When I try to do it as a servlet, Tomcat complains:
exception
javax.servlet.S ervletException : Servlet execution threw an exception
root cause
java.lang.NoCla ssDefFoundError : foobar
mytest.doGet(da tacenter_matrix .java:160)
javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:690)
javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
I searched the web all day yesterday and couldn't find why my object won't instantiate within my servlet. The servlet works so long as I don't try to instantiate a foobar object. Any idea?!?
Code:
class foobar {
int x = 0;
public void foobar() { }
}
public class mytest {
public static void main(String[] args) {
foobar blah = new foobar();
}
}
Code:
<%
class foobar {
int x = 0;
public void foobar() { }
}
foobar blah = new foobar();
%>
exception
javax.servlet.S ervletException : Servlet execution threw an exception
root cause
java.lang.NoCla ssDefFoundError : foobar
mytest.doGet(da tacenter_matrix .java:160)
javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:690)
javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:803)
Code:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
class foobar {
int x = 0;
public void foobar() { }
}
public class mytest extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
foobar blah = new foobar();
}
}
Comment