473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

instantiating objects in servlets

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:

Expand|Select|Wrap|Line Numbers
  1. class foobar {
  2.         int x = 0;
  3.         public void foobar() { }
  4. }
  5.  
  6. public class mytest {
  7.         public static void main(String[] args) {
  8.                 foobar blah = new foobar();
  9.         }
  10. }
No problem when I compile and run. Even as a jsp, it's not a problem:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. class foobar {
  3.         int x = 0;
  4.         public void foobar() { }
  5. }
  6.  
  7. foobar blah = new foobar();
  8. %>
That also works perfectly fine. When I try to do it as a servlet, Tomcat complains:

exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: foobar
mytest.doGet(datacenter_matrix.java:160)
javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.*;
  3. import javax.servlet.*;
  4. import javax.servlet.http.*;
  5.  
  6. class foobar {
  7.     int x = 0;
  8.     public void foobar() { }
  9. }
  10.  
  11. public class mytest extends HttpServlet {
  12.     public void doGet(HttpServletRequest req, HttpServletResponse res)
  13.                     throws ServletException, IOException {
  14.  
  15.         foobar blah = new foobar();
  16.     }
  17. }
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?!?
Nov 28 '08 #1
1 2408
JosAH
11,448 Expert 8TB
Your servlet does want to instantiate the objects but it can't find the appropriate class(es). Check your documentation for your servlet container: it mentions where you are supposed to store your classes (stored in a jar or just a .class file).

btw, a constructor doesn't have a return type; remove that 'void' type from your attempt of a constructor.

kind regards,

Jos
Nov 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Patrick | last post by:
I'm using Jakarta-POI to create a huge Excel spreadsheet. I get the error below when the spreadsheet grows to a large size. It seems to have something to do with the number of "cell" objects that I...
3
by: Jose Munoz | last post by:
Hi all, I want to share some data for all my applications (servlets and jsps). For this i am using a JSP to set the variables with scope=application. When i get this data from some JSP all is o.k,...
2
by: FredC | last post by:
S Name Microsoft Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600 Total Physical Memory 1,024.00 MB MDE 2003 Version 7.1.3008 ..NET Framework 1.1 Version 1.1.4322 SP1...
4
by: David Travis | last post by:
Hello, I am working on a web application, where I should generate at some scenarios large amounts of emails. I noticed that the mailing process is pretty slow, hence the page loading when these...
2
by: active | last post by:
Because of an example I followed I've been instantiating Image objects. Now I notice that the documentation says the Image class is an abstract base class. Things seem to be working! Is the...
6
by: Gary Frank | last post by:
What are the ramifications if I were to instantiate an object tens of thousands of times and add them to an array? Or hundreds of thousands of times? Do you know if the act of instantiating a...
3
by: Nagesh | last post by:
hi, I have seen the winvnc(tightvnc server) source code in this I seen that class member funtions are calling without instantiating the object i.e. like vncService::ShowDefaultProperties() where...
3
by: Bit Byte | last post by:
I have written a custom servlet engine (and "wrapper" servlets) for some legacy code (C/C++) that I have. The servlets contain the bulk of my 1st 2 layers in a 3 tier architecture - i.e. data...
3
by: Randy | last post by:
Hi, I was learning about RTTI when I ran across this example. This line, out of the example, confused me. It is declaring a pointer to a base type and instantiating it with a derived class. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.