Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ways to pass objects to a servlet?

Posted on 2006-10-26
3
Medium Priority
?
267 Views
Last Modified: 2013-11-24
hi all :)

I think the best way to show my problem with an example.
Lets say I have the following:

MyClass myInstance = new MyClass();

If I would like to pass the instance myInstance to an servlet, the way I have been using is calling a static function in the servlet
something like:

MyServlet.addMyClass(myInstance);


and in the function addMyClass I can either add myInstance to a static hashtable and when I call the servlet, I use a parameter to access the current MyClass in the hashtable (I can also do this by letting addMyclass take in the request as a parameter and add myInstance to the session instead of a hashtable).

But the problem using this method is that I need to clean the hashtable (or session) regularly so it wont fill up the memory of my server.
I can't delete myInstance from the hashtable after each call to the servlet since a user could press a servlet link more than once and then the data should still be available.

Any idea how I can do this differently so I can pass an object to an servlet which I can then use inside the doGet method?
0
Comment
Question by:nediam1234
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 1600 total points
ID: 17812308
   Hi!

Use this method to handle Applet2Servlet communications : http://www.unix.org.ua/orelly/java-ent/servlet/ch10_01.htm
Take a look at the HttpMessage support class and the methods around that class.

Regards,
  Tomas Helgi
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 17812426
0
 

Author Comment

by:nediam1234
ID: 17812886
Thank you both for your answers.
First, I'm not using an applet, I'm using jsp.

After thinking about this I see I'm talking nonsense... asked the question to quickly :)

I'm was talking about keeping object between requests, and I can't do that except by storing it somewhere of course!.

Tómas Helgi, This article (the part about HttpMessage) shows many things about server/client communication that I did not know about, good to know how I can pass objects around like this. And after reading that I know what I have to do to make my code work correctly.

Objects, I did not know that a request has setAttribute , but it's good to know that (even though it does not help here since I was actually talking about keeping data between requests).

Thanks again.. this question is not relevant anymore :)

-----
To whom it may consern: takk fyrir þetta, heimskulegt að spyrja án þess að spá mikið í þetta fyrst... en greinin sem þú sendir var góð lesning. ;)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question