ways to pass objects to a servlet?
Posted on 2006-10-26
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
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?