473,657 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

instantiating objects in servlets

2 New Member
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.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)

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 2418
JosAH
11,448 Recognized Expert MVP
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
3945
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 create. If I destroy other objects that I don't need any more, then I can create more "cell" objects. Unfortunately, I cannot destroy any more of my other objects without breaking the program. This does not appear to be a problem that is...
3
6530
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, i can see the data that i saved, but when i get access with my servlets, i can't see data saved prev. My request is simple: save data with a JSP and read this data with servlets.? please if you send me a small sample to do this. or tell me...
2
2267
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 Microsoft Visual C# .NET 69462-335-0000007-18707 Crystal Reports for Visual Studio .NET AAP50-GS0000S-WCK00C3 The code below shows the instantiation of multiple V47 objects. These
4
2518
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 emails are generated is slow too. If I will use threads to execute the mailing process the page will load quickly, and the thread will run in the background producing emails. I know that in Java environment (Servlets) developers are not...
2
1242
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 documentation wrong (it also says abstract classes cannot be instantiated)? Should I be using Bitmap instead? Is there a difference between Abstract class and Abstract base class?
6
1617
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 class takes a lot of storage or other resources? Would it be a severe performance penalty? From the .Net help doc:
3
4938
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 vncService is a class name not an refrence or instantiated object. is the above notation is possible or not?if yes how should i declare that class(vncService) so that i can call without instantiating the object. If any of u know pls answer to...
3
1959
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 layer and business logic layer respectively. Is it technically possible to use my servlets for the first two layers and then use ASP.Net for the presentation layer (i.e. using webforms etc)? The obvious "bridge" would be SOAP, but I want a more...
3
1660
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 can say the words ... yet I don't get it. What do I have, a base or a derived? Can anyone push me in the right direction. abc *abc_pointer = new xyz();
0
8838
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.